systemd

Table of Contents

Overview

Reference

Units

Syntax

[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

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

Description

Documentation

Requires

Wants

Requisite

Conflicts

Before

After

Condition…

Assert…

Service

Type

RemainAfterExit

PIDFile

BusName

NotifyAccess

ExecStart

ExecStartPre

ExecStartPost

ExecReload~

ExecStop=

ExecStopPost

RestartSec

Restart

TimeoutSec

Install

WantedBy

For sshd.service,

[Unit]
...
[Service]
...
[Install]
WantedBy=multi-user.target

When enabling sshd.service, systemd adds it to multi-user.target by following:

ln -s '/usr/lib/systemd/system/sshd.service' '/etc/systemd/system/multi-user.target/wants/sshd.service'

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-default

journalctl

journalctl                   # all
journalctl -b                # current boot
journalctl -k                # only kernel messages
journalctl -u <name>.service # unit
journalctl -f                # follow, like tail -f

Topics

Is it expected for systemd to start disabled services?

The systemctl enable and systemctl disable operations 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     disabled
enabled
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.

How-to

Links