Stopping services based on wan interface with a delay

I have an not realy stable internet and I use openwrt installed on router in bridge mode in serial to adsl modem.

when my isp messes up or my line noise goes up I get disconnected from wan side and the pppoe-wan interface goes down.
when this happens the services that are dependent on wan throws errors in the main log and pollute it unnecessary.
so for example stubby gives a lot of error and dnscrypt too and ddns and so on.

is there a way to stop these services with wan side going down (which I think happens with some services on openwrt like privoxy) and then start them after a ,say 2 sec delay, after pppoe-wan interface is up?

I would suggest to use config for those services to not show too much information in log. For example in ddns you may have a verbosity level in Advanced settings tab named Log to syslog and you can set it no logging in LuCI and that should prevent it from logging anything at all in log. You will need to consult the configuarion of all the services this way and make your changes as you see fit.

You can also stop the services altogether by installing mwan3 and using its notification techniques. You can use /etc/mwan3.user file for more info.


two good points but they are not what I asked.
I dont want to lose logs of these programs.
I want to stop there spamming the log only when the wan goes down.

the second point: I have installed mwan3 before (for testing for multi-wan redundance) but I prefer not to add another service for this and am looking to find a simpler one.

if it can be done with no delay( the 2 sec I asked) it will still be good for me.

Well then it only leaves a last option for you, hotplug.d. Add a small script in /etc/hotplug.d/net and it will be run everytime some interface changes. You can identify the changed interface and then do what you want with it.

You are not losing any logs with the above two options. You will need to consult the verbosity options in all the concerned services and make changes as you see fit.

1 Like

thanks I will check it out.

second part of your answer : I am not trying to lose or not lose logs.
I am trying to stop the program (or maybe only their logs that spams the log) when the wan side goes down.
for example I dont want stubby to give errors when wan is down but I want it to give error when wan is up.

The advanced log filtering needed can be obtained with syslog-ng, or probably rsyslogd

Restarting the service likely destroys any caches it has generated, as well as may introduce delays in connectivity.

1 Like

I know about that. but many programs dont understand not to try to connect to internet if the wan interface is down.

maybe privoxy is aware of wan interface or maybe its script knows how to handle than.
but when a program spams the logs, it doesnt help me if it is its own log. if I see for example that ddns script failed at some time for a period I dont know it that is ddns provider fault , my internet (not adsl but the internet over it) or my adsl noise side causing wan to go down.

if I can configure ddns script to for example dont try to ping internet when wan (pppoe-wan) is down.

that's it.

i know about syslog-ng ( I use it but it has timezone issues).
but it wont help with what I described.

maybe this issue doesnt have an answer.
so maybe the default scripts for them need to be changed which because my case is not that common (most poeple use ethernet for the wan that doesnt go down from router perspective) this wont be changed.

thanks for all the answers.

Have you tried creating a network/hotplug script?

1 Like

I will try that.