Semi fix for pwm
[matches/MCTX3420.git] / server / run.sh
1 #!/bin/bash
2 # Use this to quickly test run the server in valgrind
3 #spawn-fcgi -p9005 -n ./valgrind.sh
4 # Use this to run the server normally
5 #./stream &
6
7 # Check running as root
8 if [ "$(whoami)" != "root" ]; then
9         (echo "Run $0 as root.") 1>&2
10         exit 1
11 fi
12
13 # Check existence of program
14 if [ ! -e "server" ]; then
15         (echo "Rebuild server.") 1>&2;
16         exit 1
17 fi
18
19 # Identify cape-manager slots
20 slot=$(echo /sys/devices/bone_capemgr.*/slots | awk '{print $1}')
21 pwm=/sys/class/pwm/
22
23 # Load PWM module
24 #modprobe pwm_test
25 (echo am33xx_pwm > $slot) 1>&2 >> /dev/null
26 #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
27 #       echo bone_pwm_$port > $slot
28 #done
29 echo 0 > $pwm/export
30 echo 1 > $pwm/export
31 echo bone_pwm_P9_21 > $slot
32 echo bone_pwm_P9_22 > $slot
33
34 # Load ADCs
35 (echo cape-bone-iio > $slot) 1>&2 >> /dev/null
36 # Find adc_device_path
37 # NOTE: This has to be passed as a parameter, because it is not always the same. For some unfathomable reason. Hooray.
38 adc_device_path=$(dirname $(find /sys -name *AIN0))
39
40
41 # Run the program with parameters
42 # TODO: Can tell spawn-fcgi to run the program as an unprivelaged user?
43 # But first will have to work out how to set PWM/GPIO as unprivelaged user
44 fails=0
45 while [ $fails -lt 10 ]; do
46         spawn-fcgi -p9005 -n -- ./server -a "$adc_device_path"
47         if [ "$?" == "0" ]; then
48                 exit 0
49         fi
50         fails=$(( $fails + 1 ))
51         (echo "Restarting server after Fatal Error #$fails") 1>&2
52         
53 done
54 (echo "Server had too many Fatal Errors ($fails)") 1>&2
55 exit $fails
56

UCC git Repository :: git.ucc.asn.au