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!

jffs/scripts/services-start not executed after reboot

Discussion in 'Asuswrt-Merlin' started by Ribboa, Jul 5, 2018.

  1. Ribboa

    Ribboa Occasional Visitor

    Joined:
    Nov 24, 2017
    Messages:
    11
    Hi everyone,

    my router: RT-AC87U
    Firmware: 384.5

    my services-start script is not executed after a reboot.

    I put this code at the top of each script in /jffs/scripts in order to verify:
    Code:
    DATE=$(date +"%Y-%m-%d-%H%M%S")
    mkdir -p /tmp/logs
    touch /tmp/logs/$DATE-services-start
    
    this is the content of /tmp/logs/:

    Code:
    drwxrwxrwx    2 admin    root           140 Jul  5 22:12 .
    drwxrwxrwx   15 admin    root          1060 Jul  5 22:18 ..
    -rw-rw-rw-    1 admin    root             0 Feb 14  2017 2017-02-14-010035-services-start
    -rw-rw-rw-    1 admin    root             0 Feb 14  2017 2017-02-14-010036-firewall-start
    -rw-rw-rw-    1 admin    root             0 Jul  5 22:12 2018-07-05-221221-firewall-start
    -rw-rw-rw-    1 admin    root             0 Jul  5 22:12 2018-07-05-221237-post-mount
    -rw-rw-rw-    1 admin    root             0 Jul  5 22:12 2018-07-05-221244-post-mount
    
    So anyone have an idea what's wrong? I wonder what these old entries (14th Feb 2017) are all about as /tmp is tmpfs and should be only stored in RAM, right? Any ideas what's going wrong?

    Kind regards
    Ribboa
     
  2. kfp

    kfp Very Senior Member

    Joined:
    Jun 26, 2014
    Messages:
    709
    Execute bit is not set
    Code:
    chmod +x <script name>
    Edit: those are not the scripts themselves so of course execute bit is not set. I should learn to read.
     
    Last edited: Jul 6, 2018
  3. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    9,789
    Location:
    UK
    I suspect the script is actually running. The file will have that date/time because the script runs before NTP has had a chance to set the date/time. So the timestamp is the firmware's default.
     
    Ribboa, Martin - SNBuser and Twiglets like this.
  4. Ribboa

    Ribboa Occasional Visitor

    Joined:
    Nov 24, 2017
    Messages:
    11
    You are right. Obviously the script has been started too early and therefore the timestamp is "broken" and somehow my services are not started. Adding a sleep 60 at the beginning of the services-start script solved the issue for me. I just wonder why I have this problems and others seem not to have it.
     
  5. Adamm

    Adamm Part of the Furniture

    Joined:
    Mar 26, 2013
    Messages:
    2,330
    Just a minor inconvenience, easy to work around it :p

    Code:
    retry=1
    while [ "$(nvram get ntp_ready)" = "0" ] && [ "$retry" -lt "300" ]; do
        retry=$((retry+1))
        sleep 1
    done
    if [ "$retry" -ge "300" ]; then logger -st Skynet "[ERROR] NTP Failed To Start After 5 Minutes - Please Fix Immediately!"; exit 1; fi
     
    kfp likes this.
  6. skeal

    skeal Part of the Furniture

    Joined:
    Apr 30, 2016
    Messages:
    3,456
    Location:
    /etc
    Do you use FreshJR_QOS in particular the fast version? If this is the case it really messes with your startup. You may use the compatible version and it won't mess with the normal startup.
     
  7. Ribboa

    Ribboa Occasional Visitor

    Joined:
    Nov 24, 2017
    Messages:
    11
    No, I don't use it.
     
  8. Ribboa

    Ribboa Occasional Visitor

    Joined:
    Nov 24, 2017
    Messages:
    11
    Thanks, that ensures that the script wait for ntp to be ready, but unfortunately it's still too early to start nginx. I do not find any hint in the logs.
     
  9. Ribboa

    Ribboa Occasional Visitor

    Joined:
    Nov 24, 2017
    Messages:
    11
    Ok, I found something:
    Code:
    Jul  6 22:37:32 admin: Could not start Entware
    This is logged by services-start:
    Code:
    RC='/opt/etc/init.d/rc.unslung'
    
    i=30
    until [ -x "$RC" ] ; do
      i=$(($i-1))
      if [ "$i" -lt 1 ] ; then
        logger "Could not start Entware"
        exit
      fi
      sleep 1
    done
    $RC start
    And later on:
    Code:
    Jul  6 22:37:36 usb: USB ext2 fs at /dev/sda1 mounted on /tmp/mnt/entware.
    Jul  6 22:37:36 custom_script: Running /jffs/scripts/post-mount (args: /tmp/mnt/entware ) - max timeout = 120s
    I am not a bash pro, but I guess the scripts waits for the existence of /opt/etc/init.d/rc.unslung and logs "Could not start Entware" if it couldn't be found after 30 seconds.

    The post-mount script is executed 4 seconds after "Could not start Entware" has been logged.

    My conclusion: The 30 seconds are not enough time to wait for /opt being mounted. I will increase it to 60 seconds. In my opinion this should be increased in https://github.com/RMerl/asuswrt-merlin/blob/master/release/src/router/others/entware-setup.sh as well.

    Edit: With i=60 it works like a charm ;-)
     
  10. Jack Yaz

    Jack Yaz Part of the Furniture

    Joined:
    Apr 20, 2017
    Messages:
    2,469
    I start Entware in post-mount, so if the mounted drive is the entware drive, run rc.unslung. Seems much cleaner than a timeout/looping check

    Code:
    if [ "$1" = "/tmp/mnt/entware" ] ; then
        ln -nsf $1/entware /tmp/opt
        logger "$0:" "Running rc.unslung to start Entware services..."
        /opt/etc/init.d/rc.unslung start
    fi
    
     
    kfp likes this.
  11. johnathonm

    johnathonm Regular Contributor

    Joined:
    Aug 1, 2014
    Messages:
    162
    Jack,

    Question, if my entware folder is located in /tmp/mnt/sda1/entware, how would I need to modify this script?

    Thanks,
    J
     
  12. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    5,974
    Location:
    Switzerland
    This'll work for you.
    Code:
    if [ "$1" = "/tmp/mnt/sda1" ] ; then
        ln -nsf $1/entware /tmp/opt
        logger "$0:" "Running rc.unslung to start Entware services..."
        /opt/etc/init.d/rc.unslung start
    fi
     
    Jack Yaz likes this.
  13. Jack Yaz

    Jack Yaz Part of the Furniture

    Joined:
    Apr 20, 2017
    Messages:
    2,469
    I was replying but beaten to it ;-)
     
    thelonelycoder likes this.
  14. johnathonm

    johnathonm Regular Contributor

    Joined:
    Aug 1, 2014
    Messages:
    162
    You rock LC, and I love your programs. The use of a menu driven system makes life so so much easier. I really can't wait to see what you come up with next. Also, thank you for linking the lists between skynet and AB. That was awesome.
     
  15. johnathonm

    johnathonm Regular Contributor

    Joined:
    Aug 1, 2014
    Messages:
    162
    Lonelycoder,

    Is this something I can build into your section of DO NOT EDIT?

    J
     
  16. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    5,974
    Location:
    Switzerland
    Yes and no. Unless you know what you're doing I would leave things as they are. rc.unslung is started through the services-start in AB-Solution 3. AB 4 will have a totally different mechanism to start services.
     
  17. johnathonm

    johnathonm Regular Contributor

    Joined:
    Aug 1, 2014
    Messages:
    162
    I will follow your lead on this one. :)