~mil/sxmo-utils

cfc95787de4ffd5d0cf57145027ca09c356446d2 — Stacy Harper 2 months ago ff7c439 swmo
Make the modemmonitor bullet proof
M configs/appcfg/xinit_template => configs/appcfg/xinit_template +1 -1
@@ 34,7 34,7 @@ amixer set "Line Out" 50%
# not receive texts/calls!
# (there is a bit of a delay to
# give the modem some time to set up)
sleep 15 && sxmo_modemmonitortoggle.sh on &
sxmo_modemmonitortoggle.sh restart &


### Configuration Parameters ###

M scripts/modem/sxmo_modemmonitor.sh => scripts/modem/sxmo_modemmonitor.sh +2 -2
@@ 317,8 317,8 @@ mainloop() {
					sleep 3
					if [ "$TRIES" -eq 10 ]; then
						echo failed > "$MODEMSTATEFILE"
						echo "sxmo_modemmonitor: forcing modem reset">&2
						sxmo_modemmonitortoggle.sh reset #will kill the modemmonitor too
						echo "sxmo_modemmonitor: forcing modem restart">&2
						sxmo_modemmonitortoggle.sh restart #will kill the modemmonitor too
						break
					fi
				fi

M scripts/modem/sxmo_modemmonitortoggle.sh => scripts/modem/sxmo_modemmonitortoggle.sh +62 -22
@@ 10,34 10,74 @@
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

if [ "$1" = "restart" ]; then
	"$(basename "$0")" off
fi
if [ "$1" = "reset" ]; then
	#does a hard reset of the entire modem
	echo "sxmo_modemmonitortoggle: forcing modem reset">&2
	notify-send "Resetting modem, this may take a minute..."
	pkill -TERM -f sxmo_modemmonitor.sh
ensure_daemon() {
	TRIES=0
	while ! rc-service "$1" status | grep -q started; do
		if [ "$TRIES" -eq 10 ]; then
			return 1
		fi
		TRIES=$((TRIES+1))
		sudo rc-service "$1" start
		sleep 5
	done

	return 0
}

ensure_daemons() {
	if (rc-service eg25-manager status | grep -q started) &&
		(rc-service modemmanager status | grep -q started); then
		return
	fi

	echo "sxmo_modemmonitortoggle: forcing modem restart" >&2
	notify-send "Resetting modem daemons, this may take a minute..."

	sudo rc-service modemmanager stop
	sudo rc-service eg25-manager stop
	sleep 5
	while ! rc-service eg25-manager status | grep -q started; do
		sudo rc-service eg25-manager start
		sleep 2
	sleep 2

	if ! (ensure_daemon eg25-manager && ensure_daemon modemmanager); then
		printf "failed\n" > "$MODEMSTATEFILE"
		notify-send --urgency=critical "We failed to start the modem daemons. We may need hard reboot."
		return 1
	fi
}

on() {
	rm "$NOTIFDIR"/incomingcall*

	TRIES=0
	while ! printf %s "$(mmcli -L)" 2> /dev/null | grep -qoE 'Modem\/([0-9]+)'; do
		TRIES=$((TRIES+1))
		if [ "$TRIES" -eq 10 ]; then
			printf "failed\n" > "$MODEMSTATEFILE"
			notify-send --urgency=critical "We failed to start the modem monitor. We may need hard reboot."
		fi
		sleep 5
	done
	sleep 5
	sudo rc-service modemmanager start
	sleep 30

	setsid -f sxmo_modemmonitor.sh &
elif [ "$1" != "on" ] && pgrep -f sxmo_modemmonitor.sh; then

	sleep 1
}

off() {
	pkill -TERM -f sxmo_modemmonitor.sh
elif [ "$1" != "off" ] && ! pgrep -f sxmo_modemmonitor.sh; then
	setsid -f sxmo_modemmonitor.sh &
fi
}

rm "$NOTIFDIR"/incomingcall*
if [ -z "$1" ]; then
	if pgrep -f sxmo_modemmonitor.sh; then
		set -- off
	else
		set -- on
	fi
fi

# E.g. wait until process killed or started -- maybe there's a better way..
sleep 1
case "$1" in
	restart) off; ensure_daemons && on;;
	on) ensure_daemons && on;;
	off) off;;
esac

sxmo_statusbarupdate.sh