#!/bin/bash # a shell script that keeps looping until an exit code is given # if it's a 0, immediatly restart # if it's an error, pause, then restart # and one particular code, exit cleanly. ## Run the PHP script. What it returns decides on what happens next nice php -f cli-beanstalk-worker.php ERR=$? ## Possibilities # 0 - unplanned restart (aka exit;) # 1-97 - unplanned restart # 98 - planned restart # 99 - planned stop, exit. # 100 - unplanned restart if [ $ERR -eq 97 ] then # a planned pause, then restart echo "PLANNED_PAUSE - wait 2"; sleep 2; exec $0; fi if [ $ERR -eq 98 ] then # a planned restart echo "PLANNED_RESTART"; exec $0; fi if [ $ERR -eq 99 ] then # planned complete exit echo "PLANNED_SHUTDOWN"; #echo "sleep for a couple of secs first" #sleep 2 #echo DONE, $$ exit 0; fi # unplanned exit, pause, and restart echo "unplanned restart: err:" $ERR; echo "sleeping for (2) secs. - normally 10?" sleep 2 exec $0