systemd
Table of Contents
Overview

Reference
Units
Syntax
- case-sensitive
X-<name>for non-standard sections1,yes,on,true,0,no,off,falsefor booleans
[Section]
Directive1=value
Directive2=value
...
Types
| type of unit | description |
|---|---|
.service |
manage a service or application on the server |
.socket |
|
.device |
|
.mount |
|
.automount |
|
.swap |
|
.target |
synchronization points for other units when booting up or changing states |
.path |
|
.timer |
|
.snapshot |
|
.slice |
|
.scope |
Target
- Target units do not offer any additional functionality on top of the generic functionality provided by units.
- They exist merely to group units via dependencies
Paths
| path | description |
|---|---|
/lib/systemd/system |
unit files |
/run/systemd/system |
runt-ime unit definitions |
/etc/systemd/system |
overrides (unit files which take precedence) |
Special units
| Target | description |
|---|---|
default.target |
Usually, this should be aliased (symlinked) to multi-user.target or graphical.target. |

Sections
Unit
- The first section found in most unit files
- Defines metadata for the unit and configuring the relationship of the unit to other units.
Description
Documentation
Requires
- activate dependenceis and fail if they fail
Wants
- activate dependencies but don't care whether they fail or not
Requisite
- fails if the dependency is not active
Conflicts
- deactivate the dependency if it is active
Before
After
Condition…
Assert…
Service
- Defines configuration that is only applicable for services
Type
- how to manage services.
simpleis default,forkingfor services which fork,oneshotfor shot-lived process
RemainAfterExit
- with
oneshottype. active after process exits
PIDFile
- with
forkingtype |
BusName
- with
dbustype |
NotifyAccess
- with
notifytype |
ExecStart
- if path to command starts with
-, systemd considers active even if it's failed
ExecStartPre
ExecStartPost
ExecReload~
ExecStop=
- if not given, the process will be killed when stopped
ExecStopPost
RestartSec
Restart
always,on-success,on-failure,on-abnormal,on-abort,on-watchdog

TimeoutSec
- When stopping, after waiting
nseconds, systemd kills the process
Install
- The last section is often
- optional
- Defines the behavior or a unit if it is enabled or disabled
- Enabling a unit marks it to be automatically started at boot.
WantedBy
For sshd.service,
[Unit]
...
[Service]
...
[Install]
WantedBy=multi-user.target
When enabling sshd.service, systemd adds it to multi-user.target by following:
RequiredBy
Alias
Also
DefaultInstance
Commands
systemctl
systemctl start <name>.service
systemctl stop <name>.service
systemctl restart <name>.service
systemctl reload <name>.service # reload some configs while running
systemctl enable <name>.service # make service start at boot
systemctl disable <name>.service
systemctl status <name>.service # overview
systemctl show <name>.service # low-level details
systemctl list-dependencies <name>.service
systemctl list-units # only active
systemctl list-units --all # all loaded
systemctl list-unit-files # all installed
systemctl cat <name>.service # contents of unit file
systemctl edit <name>.service # edit override for unit file
systemctl edit --full <name>.service # edit unit file
systemctl daemon-reload # reload after edit
systemctl list-unit-files --type=target
systemctl get-defaultjournalctl
journalctl # all
journalctl -b # current boot
journalctl -k # only kernel messages
journalctl -u <name>.service # unit
journalctl -f # follow, like tail -fTopics
Is it expected for systemd to start disabled services?
The
systemctl enableandsystemctl disableoperations configure auto-starting of a unit.
So, starting a unit without enabling it is valid.
What is STATE from 'systemctl list-unit-files'?
$ systemctl list-unit-files --type=service
UNIT FILE STATE
[...]
chronyd.service enabled
clamd@.service static
clamd@scan.service disabledenabled- it has a symlink in a .wants directory.
disabled- it does not.
static- the service is missing the
[Install]section in its init script, so you cannot enable or disable it. Static services are usually dependencies of other services, and are controlled automatically.