systemd is the init system on most current Linux distributions. It runs as PID 1 and manages services, mounts, timers and more.
Units
Everything systemd manages is a unit. The ending of the name gives the type:
.servicea background program.socketa socket that can activate a service.targeta group of units.mounta mounted filesystem.timera schedule that activates another unit
Packaged unit files usually live in /usr/lib/systemd/system (/lib/systemd/system on some older layouts). Your own files and changes go in /etc/systemd/system, which takes priority.
A unit file
[Unit]
Description=Example web app
After=network.target
[Service]
ExecStart=/usr/local/bin/webapp
Restart=on-failure
[Install]
WantedBy=multi-user.target[Unit] describes it and its ordering, [Service] says how to run it, and [Install] says what happens when you enable it.
Everyday commands
$ systemctl status ssh
โ ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/usr/lib/systemd/system/ssh.service; enabled)
Active: active (running)Output is shortened here. The service is called sshd on Fedora and RHEL.
$ sudo systemctl start ssh
$ sudo systemctl stop ssh
$ sudo systemctl enable --now sshstart and stop act right away. enable sets a unit to start at boot, and --now also starts it immediately.
After creating or editing unit files by hand, tell systemd to reread them:
$ sudo systemctl daemon-reloadThis does not restart running services, so restart them yourself if needed.
Logs
systemd's journal collects messages from services:
$ journalctl -u ssh -n 5-u filters by unit and -n limits the number of lines. You may need sudo or membership of a log reading group.
The reference pages are online, for example systemctl.
Try it
Run systemctl list-units --type=service and pick one. Use systemctl status and systemctl cat on it to read its state and unit file. To compare with scheduled jobs, visit the processes and cron lab.
Check your understanding
Systemd Overview
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.