X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Frun.sh;h=d9cb3439aa085fd6c951a363c0c94ada51a757d7;hb=00c5659557c54258f31da4c33c078c52f3d8feb6;hp=7b3d24a016ea014f784e897dfd2f6a0d914bcae7;hpb=744b902d7f7b532ddb19d95828d8787653e1b84c;p=matches%2FMCTX3420.git diff --git a/server/run.sh b/server/run.sh index 7b3d24a..d9cb343 100755 --- a/server/run.sh +++ b/server/run.sh @@ -2,5 +2,50 @@ # Use this to quickly test run the server in valgrind #spawn-fcgi -p9005 -n ./valgrind.sh # Use this to run the server normally -spawn-fcgi -p9005 -n ./server & -./stream +#./stream & + +# Check running as root +if [ "$(whoami)" != "root" ]; then + (echo "Run $0 as root.") 1>&2 + exit 1 +fi + +# Check existence of program +if [ ! -e "server" ]; then + (echo "Rebuild server.") 1>&2; + exit 1 +fi + +# Identify cape-manager slots +slot=$(echo /sys/devices/bone_capemgr.*/slots | awk '{print $1}') + +# Load PWM module +modprobe pwm_test +(echo am33xx_pwm > $slot) 1>&2 >> /dev/null +for port in P9_21 P9_22 P9_14 P9_16 P9_29 P9_31 P9_42 P8_13 P8_19 P8_34 P8_36 P8_45 P8_46; do + echo bone_pwm_$port > $slot +done + +# Load ADCs +(echo cape-bone-iio > $slot) 1>&2 >> /dev/null +# Find adc_device_path +# NOTE: This has to be passed as a parameter, because it is not always the same. For some unfathomable reason. Hooray. +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 +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 +