copperhead
Regular Contributor
I need to pause a network monitor script during firmware updates to avoid interference. Is there a way for scripts to detect when a firmware update is being inspected / applied by the front-end UI?
I need to pause a network monitor script during firmware updates to avoid interference. Is there a way for scripts to detect when a firmware update is being inspected / applied by the front-end UI?
Is the "network monitoring" script running on the router or elsewhere like on a server? If it's on the router it's much easier. How is it being triggered to run? Via cron job?
For example, MerlinAU stops all other cron jobs from other scripts and Entware processeses such as unbound and diversion, etc before unmounting the USB and starting the flash.
The internet monitoring script is running on the router. It is a python script which was launched by the post-mount event. The script remains active indefinitely checking the internet every 30 seconds in the following order:
1. Check Internet:
x Performs ping test
x Checks DNS resolution
** If any of the above fail then ....
2. Try to Fix Internet connectivity. The script runs through each of the following checking the internet status at each level. If the internet is restored, the function is exited and the script goes back to Sleep for 30 secs then, when awake, restarts at (1) - Check Internet:
x Attempts DNS fix.
x Renews ISP DHCP lease
x Restarts WAN interface
x Restarts router
x Restarts modem
My concern has to do with when the router is checking / applying its firmware. The last time i updated the firmware, I've received notifications from the script that the internet wasn't working. It got all the way down to "Restart WAN Interface". Thankfully it never got to the "Restart Router" stage which, to me, seems like a bad idea when firmware updating.
May 5 09:05:31 custom_script: Running /jffs/scripts/service-event (args: start upgrade)
May 5 09:05:30 rc_service: httpd 4893:notify_rc start_upgrade
grep -i "start_upgrade" /tmp/syslog.log
The internet monitoring script is running on the router. It is a python script which was launched by the post-mount event. The script remains active indefinitely checking the internet every 30 seconds in the following order:
1. Check Internet:
x Performs ping test
x Checks DNS resolution
** If any of the above fail then ....
2. Try to Fix Internet connectivity. The script runs through each of the following checking the internet status at each level. If the internet is restored, the function is exited and the script goes back to Sleep for 30 secs then, when awake, restarts at (1) - Check Internet:
x Attempts DNS fix.
x Renews ISP DHCP lease
x Restarts WAN interface
x Restarts router
x Restarts modem
My concern has to do with when the router is checking / applying its firmware. The last time i updated the firmware, I've received notifications from the script that the internet wasn't working. It got all the way down to "Restart WAN Interface". Thankfully it never got to the "Restart Router" stage which, to me, seems like a bad idea when firmware updating.
There is an even earlier process which is this one:
May 5 09:05:23 custom_script: Running /jffs/scripts/service-event (args: stop upgrade)
Which means when you start an upgrade, the service-event script is triggered with the event parameters: stop upgrade
You can piggy back on this if you'd like. when the service-event receives the "stop" and "upgrade" parameters; it can shutdown your python script.
That is perfect!
So i would use the service-event: stop upgrade to stop my python script. Got it. Not that i need it but out of curiosity, what event is issued when the upgrade is complete? Dont tell me it is service-event: start upgrade. That would really mess with my mind.
if echo "$2" | /bin/grep -q "MerlinAU" ; then { /jffs/scripts/MerlinAU.sh service_event "$@" & }; fi #MerlinAU#
if [ "$1" = "stop" ] && [ "$2" = "upgrade" ]; then
PIDS="$(ps | grep '[p]ython .*/Test/test\.py' | awk '{print $1}')"
if [ -n "$PIDS" ]; then
# Graceful SIGTERM
kill $PIDS 2>/dev/null
sleep 2
# Force‑kill any survivor
for PID in $PIDS; do
if kill -0 "$PID" 2>/dev/null; then
kill -9 "$PID" 2>/dev/null
fi
done
fi
fi
May 5 09:05:23 custom_script: Running /jffs/scripts/service-event (args: stop upgrade)
May 5 09:05:31 custom_script: Running /jffs/scripts/service-event (args: start upgrade)
Fantastic explanation. I have it all implemented now and verified. Much appreciated!
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!