We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Running a script on startup



  • During the boot process of the Onion, the very last message that appears states that the nonblocking pool is initialised. This is fine however, but the scripts that I want to run on startup make use of the random number generator.

    Is there a way of ensuring that the script is run after this prompt?
    As it takes a different amount of time for this prompt to appear, sticking in a sleep statement would be inefficient and may end up waiting longer than required.

    I have added my script in /etc/rc.local, but it seems to start the script prematurely, thus causing it to quit.

    Any suggestions would be appreciated.



  • @Cooper-Chan have a look at /etc/rc.d. There you see softlinks to scripts in /etc/init.d. At boot, the 'S*' link's scripts will be called in alphabetical order (the 'K*' links are for shutdown)

    The user startup script /etc/rc.local is called from /etc/init.d/done, which is linked as /etc/rc.d/S95done.

    The random seed init however is linked as /etc/rc.d/S99urandom_seed, that's why you see rc.local called before random is ready.

    To change this order, don't change the links manually, because these are generated. Instead, disable the service you want to change the order for, edit the START=xx lines you find at the beginning of all scripts in /etc/init.d, and then re-enable it, like:

    /etc/init.d/someservice disable
    vi /etc/init.d/someservice
    # edit the START=xx line
    /etc/init.d/someservice enable
    

    However, I would not change the existing done script, as it does other things the system might rely on.

    Instead, just create your own script for example as /etc/init.d/zzready (zz prefix to make it alphabethically the last among all S99 scripts):

    #!/bin/sh /etc/rc.common
    START=99
    boot() {
      # call your startup script here
      sh /etc/mystartup.sh
    }
    

    and then enable it for autorun:

    /etc/init.d/zzready enable
    

    hope this helps!



  • Another way would be to make your startup script a "pre-startup script". Have the pre-startup script loop until the service was available, then call your actual startup script from within the pre-startup script.

    I think you could use the shell ps command to get a list of all running processes (https://explainshell.com/explain/1/ps) and check for the one you want.



  • @luz Thank you very much for taking the time to reply to my question and explaining how Linux calls the various start up scripts. I will take your suggestion of creating a new script and enabling it.

    @Jon-Gordon Thanks to you as well for your suggestion, I think the first suggestion is more of an answer I am looking for.

    All the best to the both of you!



Looks like your connection to Community was lost, please wait while we try to reconnect.