From 9450ed2057875d20cce2157aab56544255706fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Petazzoni?= Date: Sat, 14 Oct 2017 14:10:50 +0200 Subject: [PATCH] Improve error reporting (thanks @bretfisher for reporting this) --- prepare-vms/lib/aws.sh | 2 ++ prepare-vms/lib/cli.sh | 24 ++++++++++++------------ prepare-vms/lib/commands.sh | 19 ++++++++++--------- prepare-vms/lib/pssh.sh | 2 +- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/prepare-vms/lib/aws.sh b/prepare-vms/lib/aws.sh index 37e79cee..e7b47718 100644 --- a/prepare-vms/lib/aws.sh +++ b/prepare-vms/lib/aws.sh @@ -92,6 +92,8 @@ aws_kill_instances_by_tag() { aws ec2 terminate-instances --instance-ids $IDS \ | grep ^TERMINATINGINSTANCES + + info "Deleted instances with tag $TAG." } aws_tag_instances() { diff --git a/prepare-vms/lib/cli.sh b/prepare-vms/lib/cli.sh index fcc88230..aea4e956 100644 --- a/prepare-vms/lib/cli.sh +++ b/prepare-vms/lib/cli.sh @@ -13,15 +13,15 @@ die() { } error() { - echo "[$(red ERROR)] $1" + >/dev/stderr echo "[$(red ERROR)] $1" } warning() { - echo "[$(yellow WARNING)] $1" + >/dev/stderr echo "[$(yellow WARNING)] $1" } info() { - echo "[$(green INFO)] $1" + >/dev/stderr echo "[$(green INFO)] $1" } # Print a full-width separator. @@ -33,17 +33,19 @@ sep() { fi SEP=$(yes = | tr -d "\n" | head -c $[$COLUMNS - 1]) if [ -z "$1" ]; then - echo $SEP + >/dev/stderr echo $SEP else MSGLEN=$(echo "$1" | wc -c) if [ $[ $MSGLEN +4 ] -gt $COLUMNS ]; then - echo "$SEP" - echo "$1" - echo "$SEP" + >/dev/stderr echo "$SEP" + >/dev/stderr echo "$1" + >/dev/stderr echo "$SEP" else LEFTLEN=$[ ($COLUMNS - $MSGLEN - 2) / 2 ] RIGHTLEN=$[ $COLUMNS - $MSGLEN - 2 - $LEFTLEN ] - echo "$(echo $SEP | head -c $LEFTLEN) $1 $(echo $SEP | head -c $RIGHTLEN)" + LEFTSEP=$(echo $SEP | head -c $LEFTLEN) + RIGHTSEP=$(echo $SEP | head -c $RIGHTLEN) + >/dev/stderr echo "$LEFTSEP $1 $RIGHTSEP" fi fi } @@ -65,12 +67,10 @@ need_settings() { need_ips_file() { IPS_FILE=$1 if [ -z "$IPS_FILE" ]; then - echo "IPS_FILE not set." - die + die "IPS_FILE not set." fi if [ ! -s "$IPS_FILE" ]; then - echo "IPS_FILE $IPS_FILE not found. Please run: $0 ips " - die + die "IPS_FILE $IPS_FILE not found. Please run: $0 ips " fi } diff --git a/prepare-vms/lib/commands.sh b/prepare-vms/lib/commands.sh index 2aed6ba7..3c41c699 100644 --- a/prepare-vms/lib/commands.sh +++ b/prepare-vms/lib/commands.sh @@ -72,10 +72,10 @@ _cmd_deploy() { # wait until all hosts are reachable before trying to deploy info "Trying to reach $TAG instances..." while ! tag_is_reachable $TAG; do - echo -n "." + >/dev/stderr echo -n "." sleep 2 done - echo "" + >/dev/stderr echo "" sep "Deploying tag $TAG" pssh -I tee /tmp/settings.yaml < $SETTINGS @@ -105,6 +105,7 @@ _cmd_deploy() { sudo -u docker tee -a /home/docker/.ssh/authorized_keys" # On node1, create and deploy TLS certs using Docker Machine + # (Currently disabled.) true || pssh " if grep -q node1 /tmp/node; then grep ' node' /etc/hosts | @@ -217,9 +218,9 @@ _cmd_status() { need_tag $TAG describe_tag $TAG tag_is_reachable $TAG - echo "You may be interested in running one of the following commands:" - echo "$0 ips $TAG" - echo "$0 deploy $TAG " + info "You may be interested in running one of the following commands:" + info "$0 ips $TAG" + info "$0 deploy $TAG " } _cmd opensg "Open the default security group to ALL ingress traffic" @@ -321,9 +322,9 @@ _cmd_start() { if [ -n "$SETTINGS" ]; then _cmd_deploy $TAG $SETTINGS else - echo "To deploy or kill these instances, run one of the following:" - echo "$0 deploy $TAG " - echo "$0 stop $TAG" + info "To deploy or kill these instances, run one of the following:" + info "$0 deploy $TAG " + info "$0 stop $TAG" fi } @@ -377,7 +378,7 @@ pull_tag(){ need_tag $TAG link_tag $TAG if [ ! -s $IPS_FILE ]; then - echo "Nonexistent or empty IPs file $IPS_FILE" + die "Nonexistent or empty IPs file $IPS_FILE." fi # Pre-pull a bunch of images diff --git a/prepare-vms/lib/pssh.sh b/prepare-vms/lib/pssh.sh index 2095aac2..72e41f55 100644 --- a/prepare-vms/lib/pssh.sh +++ b/prepare-vms/lib/pssh.sh @@ -6,7 +6,7 @@ pssh () { HOSTFILE="ips.txt" [ -f $HOSTFILE ] || { - echo "No hostfile found at $HOSTFILE" + >/dev/stderr echo "No hostfile found at $HOSTFILE" return }