Last active
June 9, 2017 10:47
-
-
Save ukautz/7ebec96ca3e488249a02f9bef6e2a71f to your computer and use it in GitHub Desktop.
Deploy script on fortrabbit with graceful shutdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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