Skip to content

Instantly share code, notes, and snippets.

@joerocklin
Created January 6, 2015 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joerocklin/cd363a627c1be13349f5 to your computer and use it in GitHub Desktop.
Save joerocklin/cd363a627c1be13349f5 to your computer and use it in GitHub Desktop.
safe haproxy reload
#!/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/haproxy@formilux.org/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