Draining a node before deploying to it

Deploying to a host still receiving traffic means the requests in flight during the swap see a half-updated application, and there is no version of that which is correct.

touch /var/www/app/shared/.draining
sleep 15                # > check interval x unhealthy threshold

./deploy.sh

rm /var/www/app/shared/.draining

# the health endpoint returns 503 while the file exists.

A file the health endpoint checks is the simplest mechanism and works with any load balancer that does health checks at all. The sleep has to exceed the check interval multiplied by the unhealthy threshold, which is a number to look up rather than guess — too short and the balancer has not noticed yet. Connections already established still need to finish, which is what a graceful php-fpm reload handles at the other end.