github.com/blystad/deis@v0.11.0/logger/bin/boot (about) 1 #!/bin/bash 2 # 3 # This script is designed to be run inside the container 4 # 5 6 # fail hard and fast even on pipelines 7 set -eo pipefail 8 9 # set debug based on envvar 10 [[ $DEBUG ]] && set -x 11 12 # configure etcd 13 export ETCD_PORT=${ETCD_PORT:-4001} 14 export ETCD="$HOST:$ETCD_PORT" 15 export ETCD_PATH=${ETCD_PATH:-/deis/logs} 16 export ETCD_TTL=${ETCD_TTL:-10} 17 18 # fix perms on log directory 19 chmod 755 /var/log/deis 20 21 # spawn the service in the background 22 /go/bin/syslogd & 23 SERVICE_PID=$! 24 25 # smart shutdown on SIGINT and SIGTERM 26 function on_exit() { 27 kill -TERM $SERVICE_PID 28 wait $SERVICE_PID 2>/dev/null 29 exit 0 30 } 31 trap on_exit INT TERM 32 33 echo deis-logger running... 34 35 # publish the service to etcd using the injected PORT 36 if [[ ! -z $PUBLISH ]]; then 37 38 # configure service discovery 39 PORT=${PORT:-514} 40 PROTO=${PROTO:-udp} 41 42 set +e 43 44 # wait for the service to become available on PUBLISH port 45 sleep 1 && while [[ -z $(netstat -lnu | awk "\$4 ~ \".$PUBLISH\" && \$1 ~ \"$PROTO.?\"") ]] ; do sleep 1; done 46 47 # while the port is listening, publish to etcd 48 while [[ ! -z $(netstat -lnu | awk "\$4 ~ \".$PUBLISH\" && \$1 ~ \"$PROTO.?\"") ]] ; do 49 etcdctl -C $ETCD set --ttl $ETCD_TTL $ETCD_PATH/host $HOST --no-sync >/dev/null 50 etcdctl -C $ETCD set --ttl $ETCD_TTL $ETCD_PATH/port $PORT --no-sync >/dev/null 51 sleep $(($ETCD_TTL/2)) # sleep for half the TTL 52 done 53 54 # if the loop quits, something went wrong 55 exit 1 56 57 fi 58 59 wait