@@ -10,30 +10,31 @@ set -eo pipefail
1010[[ $DEBUG ]] && set -x
1111
1212# configure etcd
13- export ETCD_PORT=${ETCD_PORT:- 4001}
13+ export ETCD_PORT=" ${ETCD_PORT:- 4001} "
1414export ETCD=" $HOST :$ETCD_PORT "
15- export ETCD_PATH=${ETCD_PATH:-/ deis/ registry}
16- export HOST_ETCD_PATH=${HOST_ETCD_PATH:-/ deis/ registry/ hosts/ $HOST }
17- export ETCD_TTL=${ETCD_TTL:- 20}
15+ export ETCD_PATH=" ${ETCD_PATH:-/ deis/ registry} "
16+ export HOST_ETCD_PATH=" ${HOST_ETCD_PATH:-/ deis/ registry/ hosts/ $HOST } "
17+ export ETCD_TTL=" ${ETCD_TTL:- 20} "
1818
1919# run.sh requires $REGISTRY_PORT
20- export REGISTRY_PORT=${PORT:- 5000}
20+ export REGISTRY_PORT=" ${PORT:- 5000} "
2121
22- export BUCKET_NAME=${BUCKET_NAME:- registry}
22+ export BUCKET_NAME=" ${BUCKET_NAME:- registry} "
2323
2424# wait for etcd to be available
25- until etcdctl --no-sync -C $ETCD ls > /dev/null 2>&1 ; do
25+ until etcdctl --no-sync -C " $ETCD " ls > /dev/null 2>&1 ; do
2626 echo " waiting for etcd at $ETCD ..."
27- sleep $(( $ ETCD_TTL/ 2 )) # sleep for half the TTL
27+ sleep $(( ETCD_TTL/ 2 )) # sleep for half the TTL
2828done
2929
3030# wait until etcd has discarded potentially stale values
31- sleep $(( $ ETCD_TTL+ 1 ))
31+ sleep $(( ETCD_TTL+ 1 ))
3232
3333function etcd_set_default {
3434 set +e
35- ERROR=" $( etcdctl --no-sync -C $ETCD mk $ETCD_PATH /$1 $2 2>&1 > /dev/null) "
36- if [[ $? -ne 0 && $( echo $ERROR | grep -ive " key already exists" ) ]]; then
35+ ERROR=" $( etcdctl --no-sync -C " $ETCD " mk " $ETCD_PATH /$1 " " $2 " 2>&1 > /dev/null) "
36+
37+ if [[ $? -ne 0 ]] && echo " $ERROR " | grep -iqve " key already exists" ; then
3738 echo " etcd_set_default: an etcd error occurred ($ERROR )"
3839 echo " aborting..."
3940 exit 1
@@ -43,12 +44,12 @@ function etcd_set_default {
4344
4445# seed initial service configuration if necessary
4546etcd_set_default protocol http
46- etcd_set_default bucketName ${BUCKET_NAME}
47+ etcd_set_default bucketName " ${BUCKET_NAME} "
4748
4849# wait for confd to run once and install initial templates
49- until confd -onetime -node $ETCD --confdir /app --log-level error; do
50+ until confd -onetime -node " $ETCD " --confdir /app --log-level error; do
5051 echo " registry: waiting for confd to write initial templates..."
51- sleep $(( $ ETCD_TTL/ 2 )) # sleep for half the TTL
52+ sleep $(( ETCD_TTL/ 2 )) # sleep for half the TTL
5253done
5354
5455# ensure registry bucket exists
@@ -68,8 +69,7 @@ function on_exit() {
6869trap on_exit INT TERM
6970
7071# spawn confd in the background to update services based on etcd changes
71- confd -node $ETCD --confdir /app --log-level error --interval 5 &
72- CONFD_PID=$!
72+ confd -node " $ETCD " --confdir /app --log-level error --interval 5 &
7373
7474echo deis-registry running...
7575
@@ -87,16 +87,16 @@ if [[ ! -z $EXTERNAL_PORT ]]; then
8787
8888 # while the port is listening, publish to etcd
8989 while [[ ! -z $( netstat -lnt | awk " \$ 6 == \" LISTEN\" && \$ 4 ~ \" .$PORT \" && \$ 1 ~ \" $PROTO .?\" " ) ]] ; do
90- if etcdctl --no-sync -C $ETCD mk ${ETCD_PATH} /masterLock $HOSTNAME --ttl $ETCD_TTL > /dev/null 2>&1 \
91- || [[ ` etcdctl --no-sync -C $ETCD get ${ETCD_PATH} /masterLock` == " $HOSTNAME " ]] ; then
92- etcdctl --no-sync -C $ETCD set $ETCD_PATH /host $HOST --ttl $ETCD_TTL > /dev/null
93- etcdctl --no-sync -C $ETCD set $ETCD_PATH /port $EXTERNAL_PORT --ttl $ETCD_TTL > /dev/null
94- etcdctl --no-sync -C $ETCD update ${ETCD_PATH} /masterLock $HOSTNAME --ttl $ETCD_TTL > /dev/null
90+ if etcdctl --no-sync -C " $ETCD " mk " ${ETCD_PATH} /masterLock" " $HOSTNAME " --ttl " $ETCD_TTL " > /dev/null 2>&1 \
91+ || [[ $( etcdctl --no-sync -C " $ETCD " get " ${ETCD_PATH} /masterLock" ) == " $HOSTNAME " ]] ; then
92+ etcdctl --no-sync -C " $ETCD " set " $ETCD_PATH /host" " $HOST " --ttl " $ETCD_TTL " > /dev/null
93+ etcdctl --no-sync -C " $ETCD " set " $ETCD_PATH /port" " $EXTERNAL_PORT " --ttl " $ETCD_TTL " > /dev/null
94+ etcdctl --no-sync -C " $ETCD " update " ${ETCD_PATH} /masterLock" " $HOSTNAME " --ttl " $ETCD_TTL " > /dev/null
9595 fi
96- etcdctl --no-sync -C $ETCD set $HOST_ETCD_PATH /host $HOST --ttl $ETCD_TTL > /dev/null
97- etcdctl --no-sync -C $ETCD set $HOST_ETCD_PATH /port $EXTERNAL_PORT --ttl $ETCD_TTL > /dev/null
96+ etcdctl --no-sync -C " $ETCD " set " $HOST_ETCD_PATH /host" " $HOST " --ttl " $ETCD_TTL " > /dev/null
97+ etcdctl --no-sync -C " $ETCD " set " $HOST_ETCD_PATH /port" " $EXTERNAL_PORT " --ttl " $ETCD_TTL " > /dev/null
9898
99- sleep $(( $ ETCD_TTL/ 2 )) # sleep for half the TTL
99+ sleep $(( ETCD_TTL/ 2 )) # sleep for half the TTL
100100 done
101101
102102 # if the loop quits, something went wrong
0 commit comments