diff --git a/sw/buildroot_overlay/etc/init.d/S99puzzlefw_remotectl.sh b/sw/buildroot_overlay/etc/init.d/S99puzzlefw_remotectl.sh new file mode 100755 index 0000000..41a8da0 --- /dev/null +++ b/sw/buildroot_overlay/etc/init.d/S99puzzlefw_remotectl.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# +# Run remote control server. +# + +PIDFILE=/var/run/puzzlefw_remotectl.pid + +start() { + echo "Starting PuzzleFW remote control server ..." + [ -f $PIDFILE ] && echo " ERROR: already running" && exit 1 + start-stop-daemon -S -b -p $PIDFILE -a /opt/puzzlefw/lib/run-remotectl +} + +stop() { + echo "Stopping PuzzleFW remote control server ..." + start-stop-daemon -K -s INT -p $PIDFILE +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart|reload) + stop + sleep 1 + start + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 +esac + diff --git a/sw/buildroot_overlay/opt/puzzlefw/lib/run-remotectl b/sw/buildroot_overlay/opt/puzzlefw/lib/run-remotectl new file mode 100755 index 0000000..eb2dca0 --- /dev/null +++ b/sw/buildroot_overlay/opt/puzzlefw/lib/run-remotectl @@ -0,0 +1,39 @@ +#!/bin/sh +# +# Script to run the remote control server. +# + +PIDFILE=/var/run/puzzlefw_remotectl.pid + +# Redirect output to console. +exec &> /dev/console + +# Get MAC address without ':' separators. +serialnr=$(tr -d : < /sys/class/net/eth0/address) + +# Run remote control server. +/opt/puzzlefw/bin/remotectl --serialnr $serialnr & +serverpid=$! + +# Write PID file. +echo $serverpid > $PIDFILE + +# Wait until server exits. +wait $serverpid +status=$? + +rm -f $PIDFILE + +echo "Remote control server ended with status=${status}" + +if [ $status -eq 10 ]; then + # Got command HALT. + echo "Halting system". + halt +fi + +if [ $status -eq 11 ]; then + # Got command REBOOT. + reboot +fi +