Last active
August 23, 2022 22:34
-
-
Save wiedehopf/792aa829d8000acf30a5dad855751fe7 to your computer and use it in GitHub Desktop.
haproxy SIGTERM test
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
#!/bin/bash | |
set -e | |
function mainpid() { | |
cat /run/haproxy.pid || true | |
} | |
cycles=0 | |
while sleep "0.01"; do | |
OLDPID=$(mainpid) | |
if (( OLDPID != 0 )); then | |
echo "Stopping haproxy $OLDPID" | |
kill "$OLDPID" || true | |
fi | |
k=0 | |
while true; do | |
if (( ++k > 200 )); then | |
echo "-------------------------" | |
echo "race hit: did not terminate quick enough" | |
echo "cycle counter: $cycles" | |
exit 1 | |
fi | |
sleep "0.01" | |
PID=$(mainpid) | |
if (( PID != OLDPID || PID == 0 )); then | |
break | |
else | |
echo "waiting" | |
fi | |
done | |
echo cycle counter: $(( ++cycles )) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment