Skip to content

Instantly share code, notes, and snippets.

@wiedehopf
Last active August 23, 2022 22:34
Show Gist options
  • Save wiedehopf/792aa829d8000acf30a5dad855751fe7 to your computer and use it in GitHub Desktop.
Save wiedehopf/792aa829d8000acf30a5dad855751fe7 to your computer and use it in GitHub Desktop.
haproxy SIGTERM test
#!/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