Last active
August 29, 2015 14:13
-
-
Save chrisnew/f47dd3967a87cc9095ca to your computer and use it in GitHub Desktop.
If you're using hipache as a reverse proxy and use docker container for different virtual hosts, you can use hipache-connector.sh as a supervisor program which automatically registers and unregisters itself from the given hipache server.
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 | |
SHUTDOWN=0 | |
IP=127.0.0.1 | |
VHOST="`hostname -f`" | |
SUBDOMAIN=www | |
HIPACHE=hipache | |
DEVICE=eth0 | |
SCHEME=http | |
function register { | |
IP="`ip -4 a s scope global dev $DEVICE | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'`" | |
echo "registering $IP for $VHOST at hipache:" | |
if [ "`redis-cli --raw -h $HIPACHE exists "frontend:$VHOST"`" == 0 ]; then | |
echo -n "...create new vhost: " | |
redis-cli --raw -h $HIPACHE rpush "frontend:$VHOST" $VHOST | |
fi | |
echo -n "...adding to list: " | |
redis-cli --raw -h $HIPACHE rpush "frontend:$VHOST" "$SCHEME://$IP" | |
if [ "`redis-cli --raw -h $HIPACHE exists "frontend:$SUBDOMAIN.$VHOST"`" == 0 ]; then | |
echo -n "...create new vhost: " | |
redis-cli --raw -h $HIPACHE rpush "frontend:$SUBDOMAIN.$VHOST" $VHOST | |
fi | |
echo -n "...adding to list: " | |
redis-cli --raw -h $HIPACHE rpush "frontend:$SUBDOMAIN.$VHOST" "$SCHEME://$IP" | |
} | |
function unregister { | |
echo "unregister $IP for $VHOST at hipache:" | |
echo -n "...removing from list: " | |
redis-cli --raw -h $HIPACHE lrem "frontend:$VHOST" 0 "$SCHEME://$IP" | |
echo -n "...removing from list: " | |
redis-cli --raw -h $HIPACHE lrem "frontend:$SUBDOMAIN.$VHOST" 0 "$SCHEME://$IP" | |
SHUTDOWN=1 | |
} | |
trap register SIGHUP | |
trap unregister SIGTERM | |
trap unregister SIGINT | |
register | |
while [ $SHUTDOWN == 0 ]; do | |
sleep 5s | |
done | |
echo shutdown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment