This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upgrade to haproxy 1.8.1 * Use haproxy's new master worker, remove old iptables / sleep / lock hacks. *‼️ BREAKING CHANGE: you _must_ remove "daemon" form your custom HAPROXY_HEAD templates. * upgrade libssl to version 1.1 * bump to haproxy 1.8.2 * use the default gpg keyserver
- Loading branch information
Showing
8 changed files
with
15 additions
and
158 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,9 @@ | ||
#!/bin/bash | ||
exec 2>&1 | ||
export PIDFILE="/tmp/haproxy.pid" | ||
|
||
LOG_PREFIX="$(pwd) $0" | ||
log() { | ||
logline="[$LOG_PREFIX] $1\n" | ||
printf "$logline" >&1 | ||
} | ||
log_error() { | ||
logline="[$LOG_PREFIX] $1\n" | ||
printf "$logline" >&1 | ||
printf "$logline" >&2 | ||
} | ||
|
||
addFirewallRules() { | ||
IFS=',' read -ra ADDR <<< "$PORTS" | ||
for i in "${ADDR[@]}"; do | ||
iptables -w -I INPUT -p tcp --dport $i --syn -j DROP | ||
done | ||
} | ||
|
||
removeFirewallRules() { | ||
IFS=',' read -ra ADDR <<< "$PORTS" | ||
for i in "${ADDR[@]}"; do | ||
while iptables -w -D INPUT -p tcp --dport $i --syn -j DROP 2>/dev/null; do :; done | ||
done | ||
} | ||
|
||
reload() { | ||
log "Reloading haproxy" | ||
|
||
( | ||
flock 200 | ||
|
||
log "Dropping SYN packets with addFirewallRules" | ||
addFirewallRules | ||
|
||
# Wait to settle | ||
sleep 0.1 | ||
log "addFirewallRules done" | ||
|
||
log "Saving the current HAProxy state" | ||
socat /var/run/haproxy/socket - <<< "show servers state" > /var/state/haproxy/global | ||
log "Done saving the current HAProxy state" | ||
|
||
# Trigger reload | ||
LATEST_HAPROXY_PID=$(cat $PIDFILE) | ||
log "LATEST_HAPROXY_PID: [$LATEST_HAPROXY_PID]" | ||
|
||
WHICH_HAPROXY=$(which haproxy) | ||
|
||
log "/marathon-lb/haproxy_wrapper.py $WHICH_HAPROXY -D -p $PIDFILE -f /marathon-lb/haproxy.cfg -sf $LATEST_HAPROXY_PID 200>&-" | ||
/marathon-lb/haproxy_wrapper.py $WHICH_HAPROXY -D -p $PIDFILE -f /marathon-lb/haproxy.cfg -sf $LATEST_HAPROXY_PID 200>&- | ||
local exit_code=$? | ||
log "exit code: $exit_code" | ||
if [ $exit_code -ne 0 ]; then | ||
log_error "HAProxy reload failed" | ||
fi | ||
|
||
log "Removing firewall rules with removeFirewallRules" | ||
removeFirewallRules | ||
log "removeFirewallRules done" | ||
|
||
# Need to wait 1s to prevent TCP SYN exponential backoff | ||
sleep 1 | ||
|
||
log "Reload finished" | ||
) 200>/var/run/haproxy/lock | ||
} | ||
WHICH_HAPROXY=$(which haproxy) | ||
|
||
mkdir -p /var/state/haproxy | ||
mkdir -p /var/run/haproxy | ||
|
||
reload | ||
|
||
trap reload SIGHUP | ||
while true; do sleep 0.5; done | ||
exec $WHICH_HAPROXY -W -p $PIDFILE -f /marathon-lb/haproxy.cfg -x /var/run/haproxy/socket -sf |
This file contains 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
This file contains 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