What's new

How to make dnsmasq startup wait for USB mount?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

chrisisbd

Occasional Visitor
I run dnsmasq on my DSL-AC68U (running the Gnuton variant) with a large blacklist file that is on a USB memory stick. A recent (fairly short, half a minute or so) power failure seems to have provoked an odd problem with dnsmasq failing to see when the USB mounts after power up, but when I did 'service restart_dnsmasq' it restarted perfectly.

So, in syslog.log, after the power failure at around 21:24 last night I see:-


Code:
...
...
May  5 05:05:42 wsdd2[1631]: error: wsdd-mcast-v4: wsd_send_soap_msg: send
May  5 05:05:43 wsdd2[1631]: error: wsdd-mcast-v4: wsd_send_soap_msg: send
Mar 24 21:24:23 dnsmasq[1734]: cannot access directory /home/chris/dnsmasq.d: No such file or directory
Mar 24 21:24:23 dnsmasq[1734]: FAILED to start up
Mar 24 21:24:25 wsdd2[1631]: Terminated received.
Mar 24 21:24:26 kernel: gro disabled
Mar 24 21:24:28 dnsmasq[1750]: cannot access directory /home/chris/dnsmasq.d: No such file or directory
Mar 24 21:24:28 dnsmasq[1750]: FAILED to start up
Mar 24 21:24:28 kernel: gro enabled with interval 2
Mar 24 21:24:32 crond[1150]: time disparity of 3096979 minutes detected
Mar 24 21:24:57 dnsmasq[1847]: cannot access directory /home/chris/dnsmasq.d: No such file or directory
Mar 24 21:24:57 dnsmasq[1847]: FAILED to start up
Mar 24 21:25:27 dnsmasq[1908]: cannot access directory /home/chris/dnsmasq.d: No such file or directory
...
...

This continues all through the night until I did the 'service restart_dnsmasq' at 07:21 this morning:-

Code:
...
...
Mar 25 07:20:37 dnsmasq[14200]: cannot access directory /home/chris/dnsmasq.d: No such file or directory
Mar 25 07:20:37 dnsmasq[14200]: FAILED to start up
Mar 25 07:21:07 dnsmasq[14264]: cannot access directory /home/chris/dnsmasq.d: No such file or directory
Mar 25 07:21:07 dnsmasq[14264]: FAILED to start up
Mar 25 07:21:37 dnsmasq[14324]: cannot access directory /home/chris/dnsmasq.d: No such file or directory
Mar 25 07:21:37 dnsmasq[14324]: FAILED to start up
...
...
and after that no more errors from dnsmasq and it ran perfectly.

So why couldn't dnsmasq see the file at /home/chris/dnsmasq.d (on the USB stick) all through the night even though it was trying to restart every 30 seconds but the moment I did the 'service restart_dnsmasq' it saw the file and started up OK?

While I'm about it is there an 'elegant' way of getting dnsmasq to wait for something (like the USB mount) before starting rather than just failing until the file appears?
 
So why couldn't dnsmasq see the file at /home/chris/dnsmasq.d (on the USB stick)
What creates this directory or link? The USB would be mounted under /tmp/mnt/… Is there some command in /jffs/config/profile.add that creates this link after you login via SSH?
is there an 'elegant' way of getting dnsmasq to wait for something (like the USB mount) before starting
Restart dnsmasq inside /jffs/scripts/post-mount if the mount point $1 is the expected USB path. Only append your dnsmasq conf-dir parameter in dnsmasq.postconf if the USB path is present [ -d /tmp/mnt/USB/dnsmasq.d ] && echo "conf-dir=/tmp/mnt/USB/dnsmasq.d" >> $1
 
Yes, there is a /jffs/config/profile.add that creates /home/chris on the USB mount. Ah, yes, I think I see there may be some issues there with race conditions and such, thank you!

Presumably the script /jffs/scripts/post-mount only gets run after the USB stick has mounted? Checking for the existence of the directory before running dnsmasq is just in case something has gone wrong but the check should normally always succeed, yes?

Currently the blacklist file is updated weekly by a cron job on the DSL-AC68U itself but I'm thinking it might be cleverer to run the cron on my desktop machine and rsync the file to /tmp/mnt/ew/<something> so dnsmasq doesn't depend on anything done by profile.add. It doesn't matter if an occasional update is missed.

Thanks for your help.
 
Yes, there is a /jffs/config/profile.add that creates /home/chris on the USB mount.
Just put this in the post-mount also. profile.add only runs after an interactive login.
Checking for the existence of the directory before running dnsmasq is just in case something has gone wrong but the check should normally always succeed, yes?
It should succeed if the drive mounts and the files are still on it. The intention is to allow dnsmasq to start OK even if your USB isn’t there. By restarting dnsmasq again after the drive mounts, it will start with your custom lists.

Or take the easy way out and use Diversion for blocking.
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top