Created
October 15, 2016 22:45
-
-
Save michabbb/37a0e1f05a82233f3c97b65542083e05 to your computer and use it in GitHub Desktop.
a shell script that keeps looping until an exit code is given
This file contains 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
#!/bin/bash | |
# a shell script that keeps looping until an exit code is given | |
# if it does an exit(0), restart after a second - or if it's a declared error | |
# if we've restarted in a planned fashion, we don't bother with any pause | |
# and for one particular code, exit the script entirely. | |
# The numbers 97, 98, 99 must match what is returned from the PHP script | |
php xxxxxxxx.php | |
# -- $@ | |
ERR=$? | |
echo "exticode is: "$ERR; | |
## Possibilities | |
# 97 - planned pause/restart | |
# 98 - planned restart | |
# 99 - planned stop, exit. | |
# 0 - unplanned restart (as returned by "exit;") | |
# - Anything else is also unplanned paused/restart | |
if [ $ERR -eq "97" ] | |
then | |
# a planned pause, then restart | |
echo "97: PLANNED_PAUSE - wait 1"; | |
sleep 1; | |
exec sh $0 $@; | |
fi | |
if [ $ERR -eq "98" ] | |
then | |
# a planned restart - instantly | |
echo "98: PLANNED_RESTART"; | |
exec sh $0 $@; | |
fi | |
if [ $ERR -eq "99" ] | |
then | |
# planned complete exit | |
echo "99: PLANNED_SHUTDOWN"; | |
exit 0; | |
fi | |
# unplanned exit, pause, and restart | |
echo "unplanned restart: err:" $ERR; | |
echo "sleeping for 1 sec" | |
sleep 1 | |
exec sh $0 $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment