mirror of
https://github.com/srlabs/blue-merle.git
synced 2024-10-01 04:55:39 +00:00
ed6856c490
When toggling the switch, a lock is held for a relatively long time, preventing another toggling of the switch to be noticed. With this change, I hope we can first shutdown the modem, wait for a toggle, and then continue. We're losing the abort function but I currently don't know how we would be able to keep that functionality given that the toggle is queued and we don't get the notification.
31 lines
1.2 KiB
Bash
31 lines
1.2 KiB
Bash
#!/bin/sh
|
|
action=$1
|
|
logger -p notice -t blue-merle-toggle "Called... ${action}"
|
|
|
|
|
|
. /lib/functions/gl_util.sh
|
|
|
|
|
|
|
|
if [ "$action" = "on" ];then
|
|
mcu_send_message "Blue Merle ${action}"
|
|
echo "on" > /tmp/sim_change_switch
|
|
flock -n /tmp/blue-merle-switch.lock logger -p notice -t blue-merle-toggle "Running Stage 1" || logger -p notice -t blue-merle-toggle "Lockfile busy" &
|
|
flock -n /tmp/blue-merle-switch.lock timeout 90 /usr/bin/blue-merle-switch-stage1
|
|
|
|
elif [ "$action" = "off" ];then
|
|
# We check for any previous run and eventually execute the second stage. We could check for the age of this marker and only activate the second stage is the marker is young enough.
|
|
if [ -f /tmp/blue-merle-stage1 ]; then
|
|
flock -n /tmp/blue-merle-switch.lock || logger -p notice -t blue-merle-toggle "Lockfile busy" &
|
|
flock -n /tmp/blue-merle-switch.lock timeout 90 /usr/bin/blue-merle-switch-stage2
|
|
else
|
|
logger -p notice -t blue-merle-toggle "No Stage 1; Toggling Off"
|
|
fi
|
|
echo "off" > /tmp/sim_change_switch
|
|
|
|
else
|
|
echo "off" > /tmp/sim_change_switch
|
|
fi
|
|
logger -p notice -t blue-merle-toggle "Finished Switch $action"
|
|
sleep 1
|