Systemd on the command line
These are the notes of a training course on systemd I gave as part of my work with Truelite.
Exploring the state of a system
systemctl status [unitname [unitname..]]show status of one or more units, or of the whole system. Glob patterns also work:
systemctl status "systemd-fsck@*"
systemctl list-unitsor just
systemctlshow a table with all units, their status and their description
systemctl list-socketslists listening sockets managed by systemd and what they activate
systemctl list-timerslists timer-activated units, with information about when they last ran and when they will run again
systemctl is-active [pattern]checks if one or more units are in active state
systemctl is-enabled [pattern]checks if one or more units are enabled
systemctl is-failed [pattern]checks if one or more units are in failed state
systemctl list-dependencies [unitname]lists the dependencies of a unit, or a system-wide dependency tree
systemctl is-system-runningcheck if the system is running correctly, or if some unit is in a failed state
systemd-cgtoplike top but processes are aggregated by unit
systemd-analyzeproduces reports on boot time, per-unit boot time charts, dependency graphs, and more
Start and stop services
Similar to the System V
systemctl provides commands to start/stop/restart/reload units or services:
start: starts a unit if it is not already started
stop: stops a unit
restart: starts or restarts a unit
reload: tell a unit to reload its configuration (if it supports it)
try-restart: restarts a unit only if it is already active, otherwise do nothing, to prevent accidentally starting a service
reload-or-restart: tell a unit to reload its configuration if supported, otherwise restart it
try-reload-or-restart: tell a unit to reload its configuration if supported, otherwise restart it. If the unit is not already active, do nothing to prevent accidentally starting a service.
Changing global system state
hybrid-sleep commands to tell systemd to reboot, power off, suspend and so
switch-root also work.
emergency commands switch the system to rescue and emergency
systemctl default switches to the default mode, which also happens when
exiting the rescue or emergency shell.
Run services at boot
systemd does not implement runlevels, and services start at boot based on their dependencies.
To start a service at boot, you add to its
.service file a
dependency on a well-known
At boot, systemd brings up the whole chain of dependency started from a default unit, and that will eventually activate also your service.
systemctl get-default for what unit is currently the default in your
system. You can change it via the
systemd.unit= kernel command line,
so you can configure multiple entries in the boot loader that boot the system
running different services. For example
systemd.unit=rescue.target for a
systemd.unit=multi-user.target for a non-graphical mode, or add
.target file to implement new system modes.
systemctl list-units -t target --all for a list of all currently
available targets in your system.
systemctl enable unitnameenables the unit to start at boot, by creating symlinks to it in the
.wantsdirectory of the units listed in its
systemctl disable unitnameremoves the symlinks created by enable
systemctl reenable unitnameremoves and readds the symlinks for when you changed
systemctl start activates a unit right now, but does not automatically
enable it at boot
systemctl enable enables a unit at boot, but does not automatically start
it right now
* a disabled unit can still be activated if another unit depends on it
To disable a unit so that it will never get started even if another unit
depends on it, use
systemctl mask unitname. Use
systemctl unmask unitname
to undo the masking.
Reloading / restarting systemd
systemctl daemon-reload tells systemd to reload its configuration.
systemctl daemon-reexec tells systemd to restart iself.