A deploy that rolls back on a health check

A deploy that succeeds because the files copied is a deploy that has verified nothing.

switch_release "$new"
systemctl reload php-fpm

for i in $(seq 1 10); do
  code=$(curl -so /dev/null -w '%{http_code}' localhost/health)
  [ "$code" = 200 ] && ok=1 && break
  sleep 2
done

if [ -z "${ok:-}" ]; then
  switch_release "$previous" && systemctl reload php-fpm
  exit 1
fi

Twenty seconds of retrying before giving up, and a rollback that is the same function called with the previous release. What this does not catch is a failure that appears under real traffic rather than on a health endpoint, which is what a canary is for — but it catches a fatal error in a newly deployed file, which is the failure that actually happens.