Run script when wifi connection is up?



  • Is there any simple way to run a script any time wifi is up and running?
    Currently, I'm trying to use my Omega2 as a portable DLNA server (in order to serve content in my car to a set of tablets). But, minidlna starts before the network is ready and complains about the lack of network interface. I have to restart the service in order to solve this situation.
    I'd like to add this restart command right after the wifi connection is up (no matter what wifi is up, be it the wan connection (192.168.3.1) or the LAN (on my router or whatever).

    HotPlug could have been a way to solve this, but it is not available in the repo...



  • Omega2 (as LEDE) uses netifd:

    https://lede-project.org/docs/guide-developer/netifid

    netifd supports some hotplug events in procd, e.g. executing sctipts from /etc/hotplug.d/

    https://wiki.openwrt.org/doc/techref/hotplug

    Place your script as /etc/hotplug.d/iface/99-david-action (remember about +x rights, and use env variables like ACTION, INTERFACE and DEVICE if needed).

    Never tested it on Omega2. Let me know if it works ;-)



  • Hotplug was right under my eyes... Thanks for helping me as it does the job. My problem now is with mounts as minidlna seems to start before the MicroSD card is mounted. I'm looking for the right trigger for this one now.



  • Perhaps you should try to disable automount of SD card and add script for hotplug "block" with:

    1. mount block device
    2. start minidlna

    ;-)

    Hint:

    Place fsck + mount + minidlna in:
    /etc/hotplug.d/block/99-davids-dlna

    Remember to check if block device is your expected block device (DEVNAME, DEVPATH)

    P.S. minidlna does not need to be started before network interface is up, as long as it binds to 0.0.0.0:port (I mean: ANY:port).



  • Btw, why not just add procd service script (/etc/init.d/) script with START=99 and defined service_triggers() ?


Log in to reply
 

Looks like your connection to Onion Community was lost, please wait while we try to reconnect.