Skip to content

Commit

Permalink
fix(*): etcd_set_default and etcd_safe_mkdir raise some errors
Browse files Browse the repository at this point in the history
Currently, both `etcd_set_default` and `etcd_safe_mkdir` in
the /bin/boot scripts never fail due to `|| true`. This is usually
desired because if the key already exists, we don't want to overwrite
it. However, if there is an underlying error connecting to etcd, we
swallow that as well.

This commit exploits the fact that `etcdctl` has different exit codes
for key errors and etcd errors to swallow only the errors we wish to.
  • Loading branch information
carmstrong committed Oct 29, 2014
1 parent 3c307ea commit a139fa3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
8 changes: 7 additions & 1 deletion builder/bin/boot
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ done
sleep $(($ETCD_TTL+1))

function etcd_safe_mkdir {
etcdctl --no-sync -C $ETCD mkdir $1 >/dev/null 2>&1 || true
set +e
etcdctl --no-sync -C $ETCD mkdir $1 >/dev/null 2>&1
if [[ $? -ne 0 && $? -ne 4 ]]; then
echo "etcd_safe_mkdir: an etcd error occurred. aborting..."
exit 1
fi
set -e
}

etcd_safe_mkdir $ETCD_PATH/users
Expand Down
16 changes: 14 additions & 2 deletions controller/bin/boot
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ done
sleep $(($ETCD_TTL+1))

function etcd_set_default {
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1 || true
set +e
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1
if [[ $? -ne 0 && $? -ne 4 ]]; then
echo "etcd_set_default: an etcd error occurred. aborting..."
exit 1
fi
set -e
}

function etcd_safe_mkdir {
etcdctl --no-sync -C $ETCD mkdir $1 >/dev/null 2>&1 || true
set +e
etcdctl --no-sync -C $ETCD mkdir $1 >/dev/null 2>&1
if [[ $? -ne 0 && $? -ne 4 ]]; then
echo "etcd_safe_mkdir: an etcd error occurred. aborting..."
exit 1
fi
set -e
}

etcd_set_default protocol ${DEIS_PROTOCOL:-http}
Expand Down
8 changes: 7 additions & 1 deletion database/bin/boot
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ done
sleep $(($ETCD_TTL+1))

function etcd_set_default {
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1 || true
set +e
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1
if [[ $? -ne 0 && $? -ne 4 ]]; then
echo "etcd_set_default: an etcd error occurred. aborting..."
exit 1
fi
set -e
}

etcd_set_default engine postgresql_psycopg2
Expand Down
8 changes: 7 additions & 1 deletion registry/bin/boot
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ done
sleep $(($ETCD_TTL+1))

function etcd_set_default {
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1 || true
set +e
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1
if [[ $? -ne 0 && $? -ne 4 ]]; then
echo "etcd_set_default: an etcd error occurred. aborting..."
exit 1
fi
set -e
}

# seed initial service configuration if necessary
Expand Down
8 changes: 7 additions & 1 deletion store/monitor/bin/boot
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ PG_NUM=${PG_NUM:-128} # default for 3 OSDs
HOSTNAME=`hostname`

function etcd_set_default {
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1 || true
set +e
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1
if [[ $? -ne 0 && $? -ne 4 ]]; then
echo "etcd_set_default: an etcd error occurred. aborting..."
exit 1
fi
set -e
}

if ! etcdctl --no-sync -C $ETCD get ${ETCD_PATH}/monSetupComplete >/dev/null 2>&1 ; then
Expand Down

0 comments on commit a139fa3

Please sign in to comment.