On Fri, Sep 27, 2019 at 8:05 AM W. Michael Petullo <m...@flyn.org> wrote: > > A daemon I wrote for OpenWrt depends on a running syslogd. I use > syslog-ng, and I have noticed that its init script completes before the > daemon begins to listen on /dev/log. This causes my daemon to terminate > if it starts quickly after syslog-ng. > > There are a few obvious solutions: > > (1) My daemon could sleep and try again if its connection to > syslogd fails. > > (2) My daemon's init script could sleep for one second before > running the daemon. > > (3) Syslog-ng's init script could sleep for one second after > executing syslog-ng and before exiting. > > (3) seems the most universal, but all of these feel a little kludgy due > to the reliance on a timeout. I say this becasue you cannot precisely > predict what the timeout value should be (in practice a second or so > seems to suffice). > > Does the init system provide a more general way to solve this problem? > The START=n statements seem to impose only the ordering of init script > execution and have no bearing on whether the services the scripts run > are ready. Do I have this right? > > I did see sleep in a few other scripts such as network.
How about something like this? #!/bin/sh exitservice() { if [ -n "$!" ]; then echo Killing timout kill $! 2> /dev/null wait $! 2> /dev/null fi } timeout() { sleep 10 echo 'ERROR: socket not open. Is syslog running?' >&2 kill $$ exit 1 } trap exitservice EXIT timeout & while ! grep -q /dev/log /proc/net/unix; do sleep 1 done exit 0 Cheers, Eneas _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel