From: Sam Moore Date: Mon, 23 Sep 2013 17:52:27 +0000 (+0800) Subject: Added restart functionality to run.sh X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=febf57c25e014136bd4c4add413e7a00c599a6ea;p=matches%2FMCTX3420.git Added restart functionality to run.sh Essentially if there is a non zero (error) exit, it will restart the program. If it gets a massive number of fatal errors it will eventually give up. We should do something similar to this. Perhaps receive a certain number of fatal errors in a time interval to give up? Perhaps make the software not have Fatal errors :P Making sure cleanup code is called might be important. Also we really need the errors to show up in the GUI. Anyway, this is useful for now because it lets me do things like this: http://192.168.1.10/api/pin?type=gpo&num=13 To find the non working pins (eg: GPIO13) without restarting the server a billion times. --- diff --git a/server/run.sh b/server/run.sh index be6d4cf..9bf9cc9 100755 --- a/server/run.sh +++ b/server/run.sh @@ -33,4 +33,16 @@ adc_device_path=$(dirname $(find /sys -name *AIN0)) # Run the program with parameters # TODO: Can tell spawn-fcgi to run the program as an unprivelaged user? # But first will have to work out how to set PWM/GPIO as unprivelaged user -spawn-fcgi -p9005 -n -- ./server -a "$adc_device_path" +fails=0 +while [ $fails -lt 10 ]; do + spawn-fcgi -p9005 -n -- ./server -a "$adc_device_path" + if [ "$?" == "0" ]; then + exit 0 + fi + fails=$(( $fails + 1 )) + (echo "Restarting server after Fatal Error #$fails") 1>&2 + +done +(echo "Server had too many Fatal Errors ($fails)") 1>&2 +exit $fails +