0

I have a initscript which I would like to execute only after network connection establishment. Becasue the init script will invoke a curl call. I beleive this is rather straightforward with systemd After=network-online.target. But, how can I do this with sysvinit? The linux is a custom built using yocto. There is no systemd available.

structure of initscript:

#!/bin/bash
# description: Description comes here....

# Source function library.
. /etc/init.d/functions

start() {
    # code to start app comes here
    make curl call
}

stop() {
    # code to stop app comes here 
    # example: killproc program_name

}

case "$1" in 
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    *)
       echo "Usage: $0 {start|stop|restart}"
esac

exit 0

P.S: Please let me know if any info is missing

Preeti
  • 535
  • 1
  • 6
  • 30
  • If I recall correctly, the init scripts in /etc/init.d are called in the order specified by the numbers in the names of the script. You need to make sure your script is called after the network startup. – William Pursell Apr 14 '23 at 12:20
  • How can I check these numbers? Is there any default number for networking? – Preeti Apr 14 '23 at 12:26
  • 2
    https://refspecs.linuxfoundation.org/LSB_1.2.0/gLSB/initscrcomconv.html – William Pursell Apr 14 '23 at 12:33
  • It's been too long since I have been using systemd and have forgotten so much! Thank you for forcing me into a quick doc refresh, I like the nostalgia! The number I was thinking of are in the names of the symbolic links to the script in `/etc/rd?.d`. Each runlevel uses the order provided by the names of those links. I think it is purely lexicographic, and the convention is to use integer names. – William Pursell Apr 14 '23 at 12:38
  • 1
    So if your script is `/etc/init.d/myservice` and you want it to start in runlevel n, check the name of the link for the networking service `/etc/rcn.d`, and create a link to your script there with the appropriate name. But don't do that. Instead, follow the LSB conventions for the comment and use the tooling to install the links. – William Pursell Apr 14 '23 at 12:41
  • So, if I include `Required-Start: $network` in LSB header, then my script will be executed after networking service, right? – Preeti Apr 14 '23 at 12:57
  • 2
    sort of. It looks like the whole setup is still a mess, with distributions using bespoke tooling to install the init scripts. lsb suggests using `install_initd`, but whether or not that script is available is a different question. Looks like it might be easier to do it the old -fashioned way and just make the link yourself. – William Pursell Apr 14 '23 at 17:46

0 Answers0