@@ -16,18 +16,19 @@ export ETCD_PATH=${ETCD_PATH:-/deis/controller}
1616export ETCD_TTL=${ETCD_TTL:- 20}
1717
1818# wait for etcd to be available
19- until etcdctl --no-sync -C $ETCD ls > /dev/null 2>&1 ; do
19+ until etcdctl --no-sync -C " $ETCD " ls > /dev/null 2>&1 ; do
2020 echo " waiting for etcd at $ETCD ..."
21- sleep $(( $ ETCD_TTL/ 2 )) # sleep for half the TTL
21+ sleep $(( ETCD_TTL/ 2 )) # sleep for half the TTL
2222done
2323
2424# wait until etcd has discarded potentially stale values
25- sleep $(( $ ETCD_TTL+ 1 ))
25+ sleep $(( ETCD_TTL+ 1 ))
2626
2727function etcd_set_default {
2828 set +e
29- ERROR=" $( etcdctl --no-sync -C $ETCD mk $ETCD_PATH /$1 $2 2>&1 > /dev/null) "
30- if [[ $? -ne 0 && $( echo $ERROR | grep -ive " key already exists" ) ]]; then
29+ ERROR=" $( etcdctl --no-sync -C " $ETCD " mk " $ETCD_PATH /$1 " " $2 " 2>&1 > /dev/null) "
30+
31+ if [[ $? -ne 0 ]] && echo " $ERROR " | grep -iqve " key already exists" ]]; then
3132 echo " etcd_set_default: an etcd error occurred ($ERROR )"
3233 echo " aborting..."
3334 exit 1
@@ -37,18 +38,19 @@ function etcd_set_default {
3738
3839function etcd_safe_mkdir {
3940 set +e
40- ERROR=" $( etcdctl --no-sync -C $ETCD mkdir $1 2>&1 > /dev/null) "
41- if [[ $? -ne 0 && $( echo $ERROR | grep -ive " key already exists" ) ]]; then
41+ ERROR=" $( etcdctl --no-sync -C " $ETCD " mkdir " $1 " 2>&1 > /dev/null) "
42+
43+ if [[ $? -ne 0 ]] && echo " $ERROR " | grep -iqve " key already exists" ; then
4244 echo " etcd_safe_mkdir: an etcd error occurred ($ERROR )"
4345 echo " aborting..."
4446 exit 1
4547 fi
4648 set -e
4749}
4850
49- etcd_set_default protocol ${DEIS_PROTOCOL:- http}
50- etcd_set_default secretKey ${DEIS_SECRET_KEY:- ` openssl rand -base64 64 | tr -d ' \n' `}
51- etcd_set_default builderKey ${DEIS_BUILDER_KEY:- ` openssl rand -base64 64 | tr -d ' \n' `}
51+ etcd_set_default protocol " ${DEIS_PROTOCOL:- http} "
52+ etcd_set_default secretKey " ${DEIS_SECRET_KEY:- $( openssl rand -base64 64 | tr -d ' \n' )} "
53+ etcd_set_default builderKey " ${DEIS_BUILDER_KEY:- $( openssl rand -base64 64 | tr -d ' \n' )} "
5254etcd_set_default registrationMode " enabled"
5355etcd_set_default webEnabled 0
5456etcd_set_default unitHostname default
@@ -61,16 +63,16 @@ etcd_safe_mkdir /deis/services
6163
6264# run etcd data migrations
6365echo " controller: running etcd data migrations..."
64- for script in $( ls /app/migrations/data/* .sh) ;
66+ for script in /app/migrations/data/* .sh;
6567do
66- . $script ;
68+ . " $script " ;
6769done
6870echo " controller: done running etcd data migrations."
6971
7072# wait for confd to run once and install initial templates
71- until confd -onetime -node $ETCD --confdir /app --log-level error; do
73+ until confd -onetime -node " $ETCD " --confdir /app --log-level error; do
7274 echo " controller: waiting for confd to write initial templates..."
73- sleep $(( $ ETCD_TTL/ 2 )) # sleep for half the TTL
75+ sleep $(( ETCD_TTL/ 2 )) # sleep for half the TTL
7476done
7577
7678cd /app
@@ -87,15 +89,14 @@ sudo -E -u deis gunicorn -c deis/gconf.py deis.wsgi &
8789# smart shutdown on SIGTERM (SIGINT is handled by gunicorn)
8890function on_exit() {
8991 GUNICORN_PID=$( cat /tmp/gunicorn.pid)
90- kill -TERM $GUNICORN_PID 2> /dev/null
91- wait $GUNICORN_PID 2> /dev/null
92+ kill -TERM " $GUNICORN_PID " 2> /dev/null
93+ wait " $GUNICORN_PID " 2> /dev/null
9294 exit 0
9395}
9496trap on_exit TERM
9597
9698# spawn confd in the background to update services based on etcd changes
97- confd -node $ETCD --confdir /app --log-level error --interval 5 &
98- CONFD_PID=$!
99+ confd -node " $ETCD " --confdir /app --log-level error --interval 5 &
99100
100101echo deis-controller running...
101102
@@ -113,9 +114,9 @@ if [[ ! -z $EXTERNAL_PORT ]]; then
113114
114115 # while the port is listening, publish to etcd
115116 while [[ ! -z $( netstat -lnt | awk " \$ 6 == \" LISTEN\" && \$ 4 ~ \" .$PORT \" && \$ 1 ~ \" $PROTO .?\" " ) ]] ; do
116- etcdctl --no-sync -C $ETCD set $ETCD_PATH /host $HOST --ttl $ETCD_TTL > /dev/null
117- etcdctl --no-sync -C $ETCD set $ETCD_PATH /port $EXTERNAL_PORT --ttl $ETCD_TTL > /dev/null
118- sleep $(( $ ETCD_TTL/ 2 )) # sleep for half the TTL
117+ etcdctl --no-sync -C " $ETCD " set " $ETCD_PATH /host" " $HOST " --ttl " $ETCD_TTL " > /dev/null
118+ etcdctl --no-sync -C " $ETCD " set " $ETCD_PATH /port" " $EXTERNAL_PORT " --ttl " $ETCD_TTL " > /dev/null
119+ sleep $(( ETCD_TTL/ 2 )) # sleep for half the TTL
119120 done
120121
121122 # if the loop quits, something went wrong
0 commit comments