I have a SysV init script on Fedora 18. How can I make it start after the network is ready?

StackOverflow https://stackoverflow.com/questions/16200845

  •  11-04-2022
  •  | 
  •  

Question

I have a SysV init script on Fedora 18. Fedora 18 uses systemd (and apparently, there is no way to switch back to SysV).

My script requires the network to be ready. Currently, at the time the script runs, the network is not ready. How can I make sure that my SysV init script runs after the network is up?

The beginning of my script looks like this:

   #!/bin/bash
   #
   # chkconfig: 345 99 01
   # description: starts the xyz boot service
Was it helpful?

Solution

OK, after trying several things, I tried adding an LSB header:

### BEGIN INIT INFO
# Required-Start: $network $local_fs $named
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Starts/stops the foo service
# Description: Starts/stops the foo service
### END INIT INFO

This worked! The script now runs after the network is initialized. I guess the systemd implementation reads the LSB header.

OTHER TIPS

To run a script when the network is ready, in the [Unit] section of your systemd service file, add the following:

After=network-online.target
Wants=network-online.target

The network is defined as ready when the network management software considers the network is up (that generally means a IP address is configured and routable). For NetWorkManager, it queries dbus to get the information..

References

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top