Deep Dive: systemd Targets, Units, and Dependencies

Updated

October 30, 2026

Deep Dive: systemd Targets, Units, and Dependencies

Created by Lennart Poettering and Kay Sievers, systemd is the dominant init system and system configuration suite across enterprise Linux distributions.

+-----------------------------------------------------------+
|                     systemd Architecture                  |
|                                                           |
|  [ Unit Files: .service, .socket, .target, .mount, .timer]|
|                               |                           |
|                               v                           |
|  [ Dependency Graph Engine (After=, Requires=, Wants=) ]  |
|                               |                           |
|                               v                           |
|  [ cgroups v2 Process Isolation (/sys/fs/cgroup/system.slice)]
|                               |                           |
|                               v                           |
|  [ Integrated Ecosystem: journald, logind, networkd, udev]|
+-----------------------------------------------------------+

Units: Declarative State Configurations

Unlike SysVinit scripts, systemd uses declarative INI-style unit files placed in /usr/lib/systemd/system/ (vendor defaults) and /etc/systemd/system/ (admin overrides):

# /etc/systemd/system/sshd.service
[Unit]
Description=OpenSSH Server Daemon
Documentation=man:sshd(8)
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run

[Service]
Type=notify
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

Understanding Dependency Directives

  • Requires=: Hard dependency. If unit B is listed in unit A’s Requires=, starting A will start B. If B fails to activate, A will not start.
  • Wants=: Soft dependency. systemd attempts to start B when A starts, but failure of B does not prevent A from running.
  • After= / Before=: Ordering only, not dependency. Declares the sequence of activation without implying whether the unit must be started.
  • BindsTo=: Strongest dependency. If unit B stops or crashes, unit A is immediately shut down.

Targets: Replacing Runlevels

systemd replaces numeric runlevels with targets (.target units), which group sets of services: - emergency.target: Minimal single-process shell with root mounted read-only. - rescue.target: Single-user mode with essential filesystems mounted. - multi-user.target: Standard text-mode multi-user system (corresponds to SysV runlevel 3). - graphical.target: Multi-user system with display manager and GUI (corresponds to SysV runlevel 5).

Socket Activation

In socket activation, systemd creates and listens on a network port or UNIX socket (.socket unit) before the application starts. When the first client connects, systemd passes the open file descriptor to the newly spawned daemon (.service unit). This eliminates ordering dependencies: clients can connect to dbus or sshd while they are still loading into memory without experiencing dropped connections.