Start remote control server on boot

This commit is contained in:
Joris van Rantwijk 2024-10-01 20:45:22 +02:00
parent 3eecc2cd6c
commit 1e1b07019d
2 changed files with 74 additions and 0 deletions

View File

@ -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

View File

@ -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