Skip to content

Instantly share code, notes, and snippets.

@lozzd
Created February 23, 2015 17:20
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lozzd/adce5651587538ca034b to your computer and use it in GitHub Desktop.
#!/bin/bash
# A wrapper for our HHVM implementation to be called from systemd which
# performs the task of cleanly shutting down HHVM without us affecting
# any traffic
# Move the health check file out of the way, which will make the load balance depool this node
echo "Flipping status.php to status.php.disabled..."
mv /var/www/status.php /var/www/status.php.disabled
# Wait to see how many requests are still running
echo "Going to start asking HHVM for load before I shut it down..."
for i in `seq 1 30`; do
LOAD=`curl --silent http://localhost:9002/check-load`
if [ $? -ne 0 ]; then
echo "Couldn't curl to the HHVM admin port for some reason, going to sleep for a bit and try again just in case ($i attempts)"
sleep 1;
elif [ $LOAD -gt 0 ]; then
echo "Waiting another second (currently up to $i) because the load is still $LOAD"
sleep 1
else
echo "Load was $LOAD after $i seconds, now we can kill HHVM."
break
fi
done;
echo "Killing HHVM"
# Kill HHVM - We don't have to try too hard here, because once this script is over, systemd
# will hard kill any leftover processes.
kill `pidof hhvm`
# Wait for HHVM to be dead
sleep 2;
echo "Flipping status.php.disabled to status.php"
# Restore the docroots to their former glory.
mv /var/www/status.php.disabled /var/www/status.php
echo "All done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment