Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

fix(logger): fix publish loop #766

Merged
merged 1 commit into from
Apr 18, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions logger/bin/boot
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ SERVICE_PID=$!

# smart shutdown on SIGINT and SIGTERM
function on_exit() {
kill -TERM $SERVICE_PID
wait $SERVICE_PID 2>/dev/null
kill -TERM $SERVICE_PID
wait $SERVICE_PID 2>/dev/null
}
trap on_exit INT TERM

Expand All @@ -34,24 +34,24 @@ echo deis-logger running...
# publish the service to etcd using the injected PORT
if [[ ! -z $PUBLISH ]]; then

# configure service discovery
PORT=${PORT:-514}
PROTO=${PROTO:-tcp}
# configure service discovery
PORT=${PORT:-514}
PROTO=${PROTO:-udp}

set +e
set +e

# wait for the service to become available on PUBLISH port
sleep 1 && while [[ -z $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".$PUBLISH\" && \$1 ~ \"$PROTO.?\"") ]] ; do sleep 1; done
# wait for the service to become available on PUBLISH port
sleep 1 && while [[ -z $(netstat -lnu | awk "\$4 ~ \".$PUBLISH\" && \$1 ~ \"$PROTO.?\"") ]] ; do sleep 1; done

# while the port is listening, publish to etcd
while [[ ! -z $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".$PUBLISH\" && \$1 ~ \"$PROTO.?\"") ]] ; do
etcdctl --no-sync -C $ETCD set $ETCD_PATH/host $HOST --ttl $ETCD_TTL >/dev/null
etcdctl --no-sync -C $ETCD set $ETCD_PATH/port $PORT --ttl $ETCD_TTL >/dev/null
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
done
# while the port is listening, publish to etcd
while [[ ! -z $(netstat -lnu | awk "\$4 ~ \".$PUBLISH\" && \$1 ~ \"$PROTO.?\"") ]] ; do
etcdctl -C $ETCD set --ttl $ETCD_TTL $ETCD_PATH/host $HOST --no-sync >/dev/null
etcdctl -C $ETCD set --ttl $ETCD_TTL $ETCD_PATH/port $PORT --no-sync >/dev/null
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
done

# if the loop quits, something went wrong
exit 1
# if the loop quits, something went wrong
exit 1

fi

Expand Down