Linux 101 : How to make sure the network is available before starting a service

Among other things, Systemd also handles the network and network-online target units. 
The Target units define different states of the operating system, for example, we have the graphical target, the multi user target, ...

The "NetworkManager-wait-online.service" waits for a period of time for the networking to be set up before starting, it has the below parameters:

The waits until the network is connected.

To make sure a the network is available before a service is started, we change the below parameters:

We edit the service as below:

And we add the below parameter under the [Unit] section:

We run the below command so that the configuration is taken into account:

Linux puts systemd service files in the "/usr/lib/systemd/system/" directory. 
Parts of the service files also exist in the following directory "/etc/systemd/system".


Service files in the directory "/etc/systemd/system" have higher priority is there is any overlap.


Leave as a comment: