Skip to content

Instantly share code, notes, and snippets.

@wiedehopf
Created August 23, 2022 15:47
Show Gist options
  • Save wiedehopf/33841e36de69a318d8874e1d6b98d5ed to your computer and use it in GitHub Desktop.
Save wiedehopf/33841e36de69a318d8874e1d6b98d5ed to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
function mainpid() {
systemctl show --property MainPID haproxy | cut -d= -f2
}
while sleep 0.15; do
OLDPID=$(mainpid)
echo "Stopping haproxy"
kill "$OLDPID" || true
while true; do
sleep 0.15
PID=$(mainpid)
if (( PID != OLDPID || PID == 0 )); then
break
else
echo "waiting"
fi
done
while ! systemctl is-active --quiet haproxy; do
echo "Starting haproxy"
systemctl start haproxy || true
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment