uzbek-plus/b6p/rootfs/etc/init.d/aurora-modem

27 lines
1.7 KiB
Bash
Executable file

#!/bin/sh
# Aurora modem service (B6P). Started once by /init after USB NCM; no OpenRC in this image.
# /etc/init.d/aurora-modem start | stop | status
# start: runs '/usr/sbin/aurora-modem start' in the background (registration may take up to REG_TIMEOUT s); returns at once.
# stop: ends a start still in progress, then '/usr/sbin/aurora-modem stop' (bearer down -> MM -> BAM idle -> MSS offline -> rmtfs last).
# status: service state + controller status. Reconnect without MSS restart: 'aurora-modem disconnect' then 'aurora-modem start'.
# Kernel cmdline 'aurora.modem=off' disables autostart.
C=/usr/sbin/aurora-modem; D=/run/aurora-modem; P=$D/service.pid; L=$D/service.log
mkdir -p $D
running() { [ -f $P ] && kill -0 $(cat $P) 2>/dev/null; }
case "$1" in
start)
grep -qw aurora.modem=off /proc/cmdline && { echo "aurora-modem: disabled by cmdline"; exit 0; }
running && { echo "aurora-modem: start already in progress (pid $(cat $P))"; exit 0; }
echo "=== service start $(cut -d' ' -f1 /proc/uptime)" >> $L
( $C start >> $L 2>&1; echo "=== service start rc=$? $(cut -d' ' -f1 /proc/uptime)" >> $L ) &
echo $! > $P; echo "aurora-modem: starting (pid $!, log $L)";;
stop)
if running; then echo "aurora-modem: aborting start in progress (pid $(cat $P))"; kill -TERM $(cat $P) 2>/dev/null
pkill -TERM -P $(cat $P) 2>/dev/null; sleep 1; fi
rm -f $P; echo "=== service stop $(cut -d' ' -f1 /proc/uptime)" >> $L
$C stop >> $L 2>&1; r=$?; echo "=== service stop rc=$r" >> $L; echo "aurora-modem: stop rc=$r"; exit $r;;
status)
running && echo "service: start in progress (pid $(cat $P))" || echo "service: idle"
$C status;;
*) echo "usage: $0 start|stop|status"; exit 2;;
esac