Last active
September 8, 2022 15:33
-
-
Save wiedehopf/5acf36348de5de1941ea93c3269e0e70 to your computer and use it in GitHub Desktop.
haproxy sigterm test
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 | |
OUTPUT=run-haproxy.log | |
echo writing log to $OUTPUT | |
run=0 | |
while sleep 0.00001; do | |
echo Run $(( ++run )): starting haproxy | |
echo --------------------------------------------------- | |
/usr/local/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock | |
echo --------------------------------------------------- | |
echo Run $(( run )): exited | |
done 2>&1 | perl -pe 'use POSIX strftime; use Time::HiRes gettimeofday; | |
$|=1; | |
select((select(STDERR), $| = 1)[0]); | |
($s,$ms)=gettimeofday(); | |
$ms=substr(q(000000) . $ms,-6); | |
print strftime "[%Y-%m-%d %H:%M:%S.$ms]", localtime($s)' > $OUTPUT |
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 | |
set -e | |
function mainpid() { | |
{ cat /run/haproxy.pid || true ; } 2>/dev/null | |
} | |
cycles=0 | |
sleep_prefix=0.0001 | |
#while sleep "${sleep_prefix}${RANDOM}"; do | |
while true; do | |
OLDPID=$(mainpid) | |
if (( OLDPID > 0 )); then | |
# echo "Stopping haproxy $OLDPID" | |
kill "$OLDPID" || true | |
fi | |
k=0 | |
while true; do | |
if (( ++k > 5000 )); then | |
echo "-------------------------" | |
echo "race hit: did not terminate quick enough" | |
echo "cycle counter: $cycles" | |
exit 1 | |
fi | |
sleep "${sleep_prefix}${RANDOM}" | |
PID=$(mainpid) | |
if (( PID != OLDPID || PID == 0 )); then | |
break | |
else | |
#echo "waiting" | |
true | |
fi | |
done | |
(( ++ cycles )) | |
if (( cycles % 1000 == 0 )); then | |
echo cycle counter: $(( cycles )) | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment