1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

Addon page suppresses Dnsmasq restart

Discussion in 'Asuswrt-Merlin' started by thelonelycoder, May 22, 2020 at 2:22 PM.

  1. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    6,807
    Location:
    Switzerland
    I have a peculiar problem which I can reproduce on 384.17.
    When Changing a state through the Diversion WebUI, the following relevant events are logged in syslog:
    Code:
    rc_service: httpd 6400:notify_rc restart_diversion
    custom_script: Running /jffs/scripts/service-event (args: restart diversion)
    Diversion: WebUI action, ad-blocking state changed to off
    rc_service: service 21086:notify_rc restart_dnsmasq
    rc_service: waitting "restart_diversion" via httpd ...
    rc_service: skip the event: restart_dnsmasq.
    The httpd requests service restart_diversion which runs a Diversion file that sets the new state of services, then issues a restart of Dnsmasq.
    But that request is skipped over and consequently leaves Diversion in a state where the service is disabled in its settings, but the changes are not written to dnsmasq.conf.

    Is there any way I can force a service restart_dnsmasq?
    I have lowered the httpd wait time to 4 and 1 secs in the page: <input type="hidden" name="action_wait" value="4">
    Still no luck.
    @RMerlin ?
     
  2. dave14305

    dave14305 Part of the Furniture

    Joined:
    May 19, 2018
    Messages:
    2,935
    Location:
    USA
    I found it is too recursive to issue a service restart command when in a script (service-event) that is blocking an existing service start/restart command from completing.
     
  3. dave14305

    dave14305 Part of the Furniture

    Joined:
    May 19, 2018
    Messages:
    2,935
    Location:
    USA
    You might consider issuing "restart_diversion;restart_dnsmasq" from your page in parallel, and use dnsmasq.postconf to read the new settings from custom_settings. It's what I ended up doing in one of my pages.
     
  4. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    6,807
    Location:
    Switzerland
    This will not work for me. I first have to set the states in Diversion before I can issue a Dnsmasq restart, they can be complicated with pixelserv-tls and other services Diversion offers.
    Doing a Dnsmasq restart through the webui would trigger it without those sertings written to its config file.
     
  5. dave14305

    dave14305 Part of the Furniture

    Joined:
    May 19, 2018
    Messages:
    2,935
    Location:
    USA
    I don't know if it would make a difference, but what if you catch "restart_diversion" in service-event-end instead of service-event?
     
  6. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    6,807
    Location:
    Switzerland
    Ah, let me check that.
    But one problem still remains: When Diversion writes its config file, the associated states are written to custom_settings.txt, which then are reflected when the web page refreshes.
    This would not work wit that event-end script.
     
  7. john9527

    john9527 Part of the Furniture

    Joined:
    Mar 28, 2014
    Messages:
    6,267
    Location:
    United States
    Since restart_diversion is taking too long and tripping the timer to skip dnsmasq, it it possible to break the diversion restart into two pieces....

    diversion1 calls diversion2 calls dnsmasq

    Maybe have diversion2 wait for some event before continuing....
     
    thelonelycoder likes this.
  8. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    6,807
    Location:
    Switzerland
    But after 1 or 0 secs "spinning wait" it should still do the job.
    I might just run a delayed separate script that runs after 5 secs or so.
     
  9. john9527

    john9527 Part of the Furniture

    Joined:
    Mar 28, 2014
    Messages:
    6,267
    Location:
    United States
    I need to double check....but I think the 'skip' timer is 15sec....so the router doesn't think that diversion has completed by then...
     
  10. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    6,807
    Location:
    Switzerland
    What is that timer for then, can we add that separate timeout somehow to the page?
     
  11. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    6,807
    Location:
    Switzerland
    That syslog action posted above only takes about 1 second for Diversion to process.
     
  12. dave14305

    dave14305 Part of the Furniture

    Joined:
    May 19, 2018
    Messages:
    2,935
    Location:
    USA
    notify_rc is closed source in Merlin now, but in John's fork you can see it's waiting for the previous service command to finish before processing the next. But in service-event, you're blocking the previous event from finishing (restart_diversion) because you're waiting for restart_dnsmasq to run from within restart_diversion.

    https://github.com/john9527/asuswrt...ate/release/src/router/shared/notify_rc.c#L89

    It messes with your head. Until the rc_service and rc_service_pid nvram get cleared, I think it's never going to complete. Even service-event-end runs before the nvram is cleared.

    It's a 25 second wait in John's fork.

    Try forking service restart_dnsmasq?
     
    thelonelycoder likes this.
  13. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    6,807
    Location:
    Switzerland
    Yes, that's what I meant in a previous post.
     
  14. dave14305

    dave14305 Part of the Furniture

    Joined:
    May 19, 2018
    Messages:
    2,935
    Location:
    USA
    I think it's worth testing restart_diversion;restart_dnsmasq because it looks like they are processed sequentially in services.c ("goto again").
     
    QuikSilver and thelonelycoder like this.
  15. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    6,807
    Location:
    Switzerland
    OK, with a 10 sec delayed forked job it works, but it leaves a stale taste in my mouth. I am not happy that way.
    It would mean I'd have three states to consider, the webui, Diversion settings file and Dnsmasq.
    I might just abandon that WebUI project if there's no better way, too much work for not much gain.
     
    QuikSilver likes this.
  16. Jack Yaz

    Jack Yaz Part of the Furniture

    Joined:
    Apr 20, 2017
    Messages:
    3,374
    Would
    Code:
    exec service restart_dnsmasq
    
    work? I haven't tested it myself, away from router
     
  17. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    6,807
    Location:
    Switzerland
    Nope: rc_service: skip the event: restart_dnsmasq.
     
  18. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    6,807
    Location:
    Switzerland
    Diversion is - lets say - complicated with how certain events are executed. Which means I cannot have the web page issue a Dnsmasq restart.
    It all has to run in precise order and only Diversion itself can handle that sequence properly.
     
    L&LD likes this.
  19. heysoundude

    heysoundude Very Senior Member

    Joined:
    Sep 20, 2016
    Messages:
    882
    Uh oh. Something tells me your weekend is going to get eaten up by this. But we’ll benefit from the resulting update...somehow and eventually.
    Go team!


    Sent from my iPhone using Tapatalk
     
    QuikSilver likes this.
  20. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    6,807
    Location:
    Switzerland
    Looks like if I set <input type="hidden" name="action_wait" value="10"> and a delayed Dnsmasq by also 10 secs it works.
    Or would that trigger a cat and mouse game down the road?