Created
August 8, 2016 17:39
-
-
Save pinglamb/9ef0440d0c1a8ccc02ec4e4388eb1b81 to your computer and use it in GitHub Desktop.
Haproxy X Docker
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
FROM haproxy:latest | |
RUN apt-get update | |
RUN apt-get install -y netcat-openbsd | |
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg | |
EXPOSE 80 |
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
global | |
log 127.0.0.1 local0 notice | |
maxconn 2000 | |
stats socket /var/run/haproxy.sock mode 600 level admin | |
defaults | |
log global | |
mode http | |
option httplog | |
option dontlognull | |
retries 3 | |
option redispatch | |
timeout connect 5000 | |
timeout client 10000 | |
timeout server 10000 | |
frontend gitlab | |
bind *:8888 | |
mode http | |
stats enable | |
stats refresh 30s | |
stats uri /haproxy?stats | |
default_backend gitlab | |
backend gitlab | |
balance roundrobin | |
mode http | |
option httpchk GET / | |
http-check expect ! rstatus ^5 | |
server gitlab1 192.168.99.100:10080 check | |
server gitlab2 192.168.99.100:10081 check |
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
#!/bin/bash | |
SLOT1='gitlab1' | |
SLOT2='gitlab2' | |
SLOT=`docker exec -it gitlab-haproxy bash -c 'echo "show stat" | nc -U /var/run/haproxy.sock' | grep DOWN | cut -f2 -d',' | head -n 1` | |
if [ -z "$SLOT" ]; then | |
echo 'No slot is available for docker-compose up' | |
exit | |
fi | |
cd $SLOT | |
docker-compose up -d | |
echo "Waiting the new server to go up ..." | |
CURRENT=0 | |
TIMEOUT=60 | |
RETRY_EVERY=5 | |
DOWN=$SLOT | |
while [ $CURRENT -lt $TIMEOUT ] && [ -n "$DOWN" ]; | |
do | |
CURRENT=$(($CURRENT+$RETRY_EVERY)) | |
sleep $RETRY_EVERY | |
DOWN=`docker exec -it gitlab-haproxy bash -c 'echo "show stat" | nc -U /var/run/haproxy.sock' | grep $SLOT | grep DOWN | cut -f2 -d',' | head -n 1` | |
echo $CURRENT | |
echo $DOWN | |
done | |
if [ -n "$DOWN" ]; then | |
echo 'Timeout. Failed to stop the old server.' | |
else | |
if [ $SLOT1 == $SLOT ]; then | |
cd ../$SLOT2 | |
else | |
cd ../$SLOT1 | |
fi | |
docker-compose stop | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment