Skip to content

Commit

Permalink
log output to a file if $cloud is defined
Browse files Browse the repository at this point in the history
This eliminates the risk of losing crucial debug output in a
long mkcloud run because you forgot to redirect to a file and
the terminal/screen/tmux scrollback buffer wasn't big enough.

If the 'help' argument is passed, it is assumed that logging
is not required.  Otherwise, a warning is emitted if logging
is not possible due to $cloud not being set.

Closes #1191.
  • Loading branch information
Adam Spiers committed Sep 6, 2016
1 parent 41562a2 commit f9d0b07
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/mkcloud
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
# 2. This tool relies on the script qa_crowbarsetup.sh
# 3. Please 'export' environment variables according to your needs.

if [ -n "$cloud" ]; then
: ${log_dir:=/var/log/mkcloud/$cloud}
mkdir -p "$log_dir"
log_file=$log_dir/`date -Iseconds`.log
exec > >(tee -ia $log_file)
exec 2> >(tee -ia $log_file >&2)
elif ! [[ " $@ " =~ " help " ]]; then
echo "WARNING: \$cloud not set, so won't log to a file" >&2
fi

if [[ $debug_mkcloud = 1 ]] ; then
set -x
Expand Down

0 comments on commit f9d0b07

Please sign in to comment.