Systemd units basics

unit - resource that system operates.

Systemd operates unit files which can be multiple types .service, .socket, .device etc. To start process we need only .service file.

Unit files mostly stored in /etc/systemd/system. There may be other directories with units but this one has maximum priority.

For example system units are in /lib/systemd/system. To override system unit, copy file from /lib/systemd/system to /etc/systemd/system and edit.

To override only specific directives, for unit named unit_name.service create unit_name.service.d directory in the /etc/systemd/system and place .conf file there with overridden or extended attributes.

Runtime units placed in /run/systemd/system, this directory can be used to change units for session but changes will be lost after reboot.

Sections

custom user sections start with X-

Directive1=

values

For booleans you can use:

Directives in [Unit] section

Directives in [Install] section

[Install] section used to define behavior when service enabled or disabled.

WantedBy= - similar to Wants= in [Unit] section but related to called instead of caller: If current unit has WantedBy=multi-user.target, the directory multi-user.target.wants will be created in /etc/systemd/system (if not already available) and symlink to current unit will be created in that dir when unit is enabled.

Directives in [Service] section

Section available only for .servicees. Should provide Type= which tells systemd how to:

1. Call service process

2. Find out its state

Types:

starting process in service

Template units

Example of such unit: [email protected]

Instantiation of unit: [email protected]

An instance file is usually created as a symbolic link to the template file, with the link name including the instance identifier.

In the template it's possible to use variables:

Also

#systemd
0
Ivan Borshchov profile picture
Dec 26, 2016
by Ivan Borshchov
Did it help you?
Yes !
No

Best related