2

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
Matt Fichman
  • 5,458
  • 4
  • 39
  • 59

2 Answers2

1

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.

Matt Fichman
  • 5,458
  • 4
  • 39
  • 59
  • 1
    According [Running Services After the Network is up](http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/) from the systemd documentation, $network from LSB header is translated into the network-online target both for the After and Wants directive of your unit. – Dereckson Nov 05 '14 at 23:02
0

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

Dereckson
  • 1,340
  • 17
  • 30