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
7 if [[ "$(uname -m)" != *arm* ]]; then
8 echo Not running on the BBB
9 # Use this to quickly test run the server in valgrind
10 spawn-fcgi -p9005 -n ./valgrind.sh
11 # Use this to run the server normally
16 # Check running as root
17 if [ "$(whoami)" != "root" ]; then
18 (echo "Run $0 as root.") 1>&2
22 # Check existence of program
23 if [ ! -e "server" ]; then
24 (echo "Rebuild server.") 1>&2;
29 echo Rotating the system logs
30 logrotate -f /etc/logrotate.d/mctxserv.conf
32 # Identify cape-manager slots
33 slot=$(echo /sys/devices/bone_capemgr.*/slots | awk '{print $1}')
37 if [ $(cat $slot | grep am33xx_pwm -c) -gt 0 ]; then
38 echo am33xx_pwm already loaded, not loading again;
40 echo Enabling PWM driver am33xx_pwm
41 echo am33xx_pwm > $slot
44 # Safe pins that won't interfere with one another
45 #ports=(P9_22 P9_42 P9_16 P8_13 P9_28);
46 #portnumbers=(0 2 4 6 7);
47 #Full correspondence from pwm0-pwm7
48 ports=(P9_22 P9_21 P9_42 P9_14 P9_16 P8_19 P8_13 P9_28);
49 portnumbers=(0 1 2 3 4 5 6 7);
51 # They must be exported at this stage, before the device tree
52 # overlay for that pin is enabled.
53 for ((c=0; c < ${#ports[*]}; c++)); do
54 if [ ! -d $pwm/pwm${portnumbers[$c]} ]; then
55 echo Exporting PWM ${portnumbers[$c]} \(${ports[$c]}\)
56 echo ${portnumbers[$c]} > $pwm/export
58 echo PWM ${portnumbers[$c]} already enabled
61 if [ $(cat $slot | grep ${ports[$c]} -c) -gt 0 ]; then
62 echo PWM pin ${ports[$c]} already enabled, not enabling again
64 (echo bone_pwm_${ports[$c]} > $slot) 1>&2 >> /dev/null
69 if [ $(cat $slot | grep BB-ADC -c) -gt 0 ]; then
70 echo BB-ADC already loaded, not loading again;
73 (echo BB-ADC > $slot) 1>&2 >> /dev/null
76 # Find adc_device_path
77 # NOTE: This has to be passed as a parameter, because it is not always the same. For some unfathomable reason. Hooray.
78 #adc_device_path=$(dirname $(find /sys -name *AIN0))
84 echo "Parameters are: $parameters"
86 # Run the program with parameters
87 # TODO: Can tell spawn-fcgi to run the program as an unprivelaged user?
88 # But first will have to work out how to set PWM/GPIO as unprivelaged user
90 while [ $fails -lt 10 ]; do
91 spawn-fcgi -p9005 -n -- ./server $parameters
93 if [ "$error" == "0" ]; then
96 fails=$(( $fails + 1 ))
97 (echo "Restarting server after Fatal Error #$fails") 1>&2
100 (echo "Server had too many Fatal Errors ($fails)") 1>&2