[Solved] Scripts in hotplug.d/net not firing

Hi,

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.

root@OpenWrt:~# ps | grep hotplug
 2725 ntp       1120 S    /usr/sbin/ntpd -n -N -S /usr/sbin/ntpd-hotplug -p 0.openwrt.pool.n
11965 root      1120 R    grep hotplug

Try placing the script under the iface directory.

4 Likes

I really think you want to put your script in /etc/hotplug.d/iface.

I don’t know what Environment Variables the hotplug.d/net uses. It isn’t noted in the wiki but you can see most of others here.

You can create a /etc/hotplug.d/net/00-logger script to see what Environment Variables it is providing.

cat << "EOF" > /etc/hotplug.d/net/00-logger
logger -t hotplug $(env)
EOF

Edit - @vgaetera beat me to it :grinning:

5 Likes

Hi,

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! :slight_smile:

2 Likes

I have updated the wiki with the Environment Variables for /etc/hotplug.d/net.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.