Created
January 6, 2015 21:35
-
-
Save joerocklin/cd363a627c1be13349f5 to your computer and use it in GitHub Desktop.
safe haproxy reload
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 | |
# This checks which ports haproxy currently is listening on, temporarily drops SYN packets | |
# to prevent new connections, reloads haproxy, then allows SYNs again. | |
# | |
# Based on info from here: | |
# * https://github.com/aws/opsworks-cookbooks/pull/40 | |
# * http://www.mail-archive.com/[email protected]/msg06885.html | |
#set -x | |
haports=`netstat -antp | grep LISTEN | grep haproxy | awk '{print $4}' | cut -d':' -f2 | sort -un` | |
for i in $haports; do | |
iptables -I INPUT -p tcp --dport $i --syn -j DROP | |
done | |
sleep 1 | |
service haproxy reload | |
for i in $haports; do | |
iptables -D INPUT -p tcp --dport $i --syn -j DROP | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment