I have created the following script in hotplug.d/net to gracefully shutdown my router when eth0 link (wan) is down. My Openwrt router is powered by a battery, the aim is to have a proper shutdown of the system on power outage. However, when eth0 is down nothing happens... not even the logging part befor the conditional execution at the begining of the script. I heard that hotplug.d is not any more working and we need to use procd instead, is this true? If not, how can I make the scripts under hotplug.d/net work when network events are triggered?
#!/bin/sh
echo hotplug/net: $ACTION $INTERFACE >> /tmp/ups.log
logger -t hotplug "ups script $ACTION $INTERFACE"
[ "$ACTION" = "ifdown" -a "$INTERFACE" = "wan" ] && {
logger -t hotplug "eth0 down - traced by ups.sh"
sleep 180
status=$(ifconfig eth0 | grep -E '(UP\sBROADCAST\sRUNNING\sMULTICAST)')
if [[ "$status" ]]; then
#echo "eth0 is UP"
logger "eth0 link restored - traced by ups.sh"
else
#echo "eth0 is DOWN"
logger -t hotplug "Halting system - traced by ups.sh"
poweroff
fi
}
The output of ps | grep hotplug is given below. Seems that hotplug is only trigerring ntpd events.
The script is now working in hotplug.d/iface. I have seen in other posts that scripts in hotplug.d/iface are excuted once at boot time reason for which they should be placed in hotplug.d/net... However the solution you provided works. Thanks.
No. Scripts in /etc/hotplug.d/net respond only to Triggered Network-related events, while scripts in /etc/hotplug.d/iface respond only to Triggered Interface events: LAN/WAN/etc. is connected/disconnected.
So, /etc/hotplug.d/iface is the correct place for your script.
Scripts in /etc/hotplug.d/iface will all run based on their alphabetic order (thus the numeric prefix used on hotplug scripts) when the trigger event fires. This is true of all the `/etc/hotplug.d/*’ directories whenever their particular trigger events fire.
If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.
Thanks!