Rain WikiWindows · Linux · Android

systemd units and systemctl

ServiceDistributions with systemd

A systemd unit is a configuration object that systemd, the init system of most Linux distributions, manages: services, sockets, timers, mounts and more. Units are described by unit files such as /etc/systemd/system/<name>.service and controlled with the systemctl command.

1Unit types

.service runs a program, .socket starts a service when a connection arrives, .timer runs a unit on a schedule, .mount and .automount handle file systems, .target groups units into states such as multi-user.target.

2Where unit files live

Packages install units in /usr/lib/systemd/system (or /lib/systemd/system). Local changes belong in /etc/systemd/system, which takes precedence. systemctl edit <unit> creates a drop-in override instead of changing the packaged file.

3Everyday commands

systemctl status <unit> shows state and the last log lines. 'start', 'stop' and 'restart' act now; 'enable' and 'disable' control starting at boot; 'enable --now' does both. systemctl --failed lists failed units, and systemctl daemon-reload rereads unit files after changes.

How to check a failing service

  1. List failed units: systemctl --failed
  2. Show the state and recent messages: systemctl status <unit>
  3. Read the full log of this boot: journalctl -u <unit> -b
  4. After fixing the configuration: sudo systemctl restart <unit>

Cautions

  • Change packaged units with systemctl edit, not by editing files in /usr/lib/systemd/system: updates overwrite them.
  • Do not disable units you do not know, such as systemd-journald or dbus.

Sources

  1. systemctl(1) man7.org
  2. systemd.unit(5) man7.org
  3. systemd.timer(5) man7.org

Last reviewed: