Skip to content

Instantly share code, notes, and snippets.

@ukautz
Last active June 9, 2017 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukautz/7ebec96ca3e488249a02f9bef6e2a71f to your computer and use it in GitHub Desktop.
Save ukautz/7ebec96ca3e488249a02f9bef6e2a71f to your computer and use it in GitHub Desktop.
Deploy script on fortrabbit with graceful shutdown
<?php
declare(ticks = 1);
// Your graceful shutdown handler
function exitGracefully($signal) {
// do stuff, then end with exit code 0, so that the deploy can continue
// or exit with non-zero code, so that the deploy aborts
echo "Shutting down gracefully\n";
exit(0);
}
// Set graceful shutdown handler 10 minutes, reduced by the time the
// graceful handler requires to shut down everything. So 9:30 min in
// this example:
pcntl_signal(SIGALRM, 'exitGracefully', true);
pcntl_alarm(60 * 10 - 30);
// Run your actual deploy script, simulated by a never-ending-loop
while (true) {
echo "Running post deploy stuff..\n";
sleep(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment