X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Frun.sh;h=c2bd504f95067bf1df36d47c75566ba7dd18c43b;hb=f858232d7c564f14e6d2fb9d616f8e12a1ec9171;hp=18af55b05e1a2477cf8838e6a750acea08f936de;hpb=dbbc588b45c0a99b1cccae60369bf183242854e1;p=matches%2FMCTX3420.git diff --git a/server/run.sh b/server/run.sh index 18af55b..c2bd504 100755 --- a/server/run.sh +++ b/server/run.sh @@ -4,53 +4,98 @@ # Use this to run the server normally #./stream & +if [[ "$(uname -m)" != *arm* ]]; then + echo Not running on the BBB + # Use this to quickly test run the server in valgrind + spawn-fcgi -p9005 -n ./valgrind.sh + # Use this to run the server normally + #./stream & + exit 0 +fi + # Check running as root if [ "$(whoami)" != "root" ]; then - (echo "Run $0 as root.") 1>&2 - exit 1 + (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 + (echo "Rebuild server.") 1>&2; + exit 1 fi +# Rotate the logs +echo Rotating the system logs +logrotate -f /etc/logrotate.d/mctxserv.conf + # Identify cape-manager slots slot=$(echo /sys/devices/bone_capemgr.*/slots | awk '{print $1}') pwm=/sys/class/pwm/ # 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 -echo 0 > $pwm/export -echo 1 > $pwm/export -echo bone_pwm_P9_21 > $slot -echo bone_pwm_P9_22 > $slot +if [ $(cat $slot | grep am33xx_pwm -c) -gt 0 ]; then + echo am33xx_pwm already loaded, not loading again; +else + echo Enabling PWM driver am33xx_pwm + echo am33xx_pwm > $slot +fi; + +# Safe pins that won't interfere with one another +#ports=(P9_22 P9_42 P9_16 P8_13 P9_28); +#portnumbers=(0 2 4 6 7); +#Full correspondence from pwm0-pwm7 +ports=(P9_22 P9_21 P9_42 P9_14 P9_16 P8_19 P8_13 P9_28); +portnumbers=(0 1 2 3 4 5 6 7); +# Enable PWM pins +# They must be exported at this stage, before the device tree +# overlay for that pin is enabled. +for ((c=0; c < ${#ports[*]}; c++)); do + if [ ! -d $pwm/pwm${portnumbers[$c]} ]; then + echo Exporting PWM ${portnumbers[$c]} \(${ports[$c]}\) + echo ${portnumbers[$c]} > $pwm/export + else + echo PWM ${portnumbers[$c]} already enabled + fi; + + if [ $(cat $slot | grep ${ports[$c]} -c) -gt 0 ]; then + echo PWM pin ${ports[$c]} already enabled, not enabling again + else + (echo bone_pwm_${ports[$c]} > $slot) 1>&2 >> /dev/null + fi; +done; # Load ADCs -(echo cape-bone-iio > $slot) 1>&2 >> /dev/null +if [ $(cat $slot | grep BB-ADC -c) -gt 0 ]; then + echo BB-ADC already loaded, not loading again; +else + echo Enabling BB-ADC + (echo BB-ADC > $slot) 1>&2 >> /dev/null +fi; + # 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)) +#adc_device_path=$(dirname $(find /sys -name *AIN0)) + +# Get the parameters +. parameters + +echo "Parameters are: $parameters" # 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 - + spawn-fcgi -p9005 -n -- ./server $parameters + error=$? + if [ "$error" == "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 -