Unit dependencies and unit file structure

Services are started as standalone, or sometimes as dependencies of other services. For example, let's assume a socket unit is enabled, but the service unit with the same socket name is not, then the service will automatically get started when a request is made on the network socket. Similarly, the service can also be triggered by the path unit when a filesystem path condition is met. The following command is used to list the dependency tree of the specified unit:

# systemctl list-dependencies sshd

Starting with CentOS 7, systemd provides a uniform interface to start unit files from their storage loaction. The locations of the unit file stored in the system are as follows:

  • /usr/lib/systemd/system/: It contains system default unit files
  • /etc/systemd/system: It contains system-specific parameters to modify the default behavior of systemd
  • /run/systemd/system/: It contains the runtime configuration of unit files

The structure of a unit file is shown in the following screenshot:

The preceding unit file can be broken down into following three sections:

  • Unit: This section describe the unit type and its dependencies, if any. It also contains the After statement and the Before statement. These statements define the dependencies of the unit. The Before statement says that this unit should be started before the specified unit. The After statement says that this unit should be started after starting the specified units.
  • Service: This section contains a description of how to start and stop the service. The line beginning with the ExecStart parameter describes how to start the unit and the line beginning with the ExecStop parameter describes how to stop the unit.
  • Install: This section contains a line beginning with the WantedBy parameter, which states the target of this application. Target units are the equivalent of runlevels, which we had in CentOS 6 and earlier versions.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.84.171