Created
June 23, 2014 17:27
-
-
Save andyshinn/605c5bdb4d126464fbc8 to your computer and use it in GitHub Desktop.
HAProxy and Confd Docker startup script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -eo pipefail | |
| export SHELL="/bin/bash" | |
| readonly ETCD_PORT=4001 | |
| readonly ETCD_IP=172.17.42.1 | |
| readonly ETCD=$ETCD_IP:$ETCD_PORT | |
| readonly HAPROXY_PIDS="/var/run/haproxy.pid" | |
| readonly HAPROXY_CFG="/etc/haproxy/haproxy.cfg" | |
| checkpid() { | |
| local pid=$1 | |
| if [[ ! -e /proc/$pid ]]; then | |
| return 2 | |
| fi | |
| } | |
| checkallpids() { | |
| local pids=$1 | |
| for pid in $pids; do | |
| checkpid $pid | |
| done | |
| } | |
| start_haproxy() { | |
| haproxy -f $HAPROXY_CFG -p $HAPROXY_PIDS | |
| local pids=$( < $HAPROXY_PIDS) | |
| while [[ $? -eq 0 ]]; do | |
| sleep 5 | |
| checkallpids $pids | |
| done | |
| } | |
| codep() { | |
| set -eo monitor | |
| trap 'kill $(jobs -p) &> /dev/null' EXIT | |
| trap 'exit 2' CHLD | |
| for child in "$@"; do | |
| eval "$child &" | |
| done | |
| wait | |
| } | |
| start() { | |
| nginx -v | |
| codep 'start_haproxy' \ | |
| 'confd -verbose -interval 30 -node $ETCD -config-file /etc/confd/conf.d/firehose-nginx.toml' | |
| } | |
| start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment