These are the notes of a training course on systemd I gave as part of my work with Truelite.
There is quite a lot of material, so I split them into a series of posts, running once a day for the next 9 days.
For example, this unit continuously plays an alarm sound when the system is in emergency or rescue mode:
[Unit] Description=Beeps when in emergency or rescue mode DefaultDependencies=false StopWhenUnneeded=true [Install] WantedBy=emergency.target rescue.target [Service] Type=simple ExecStart=/bin/sh -ec 'while true; do /usr/bin/aplay -q /tmp/beep.wav; sleep 2; done'
Units can be described by configuration files, which have different extensions based on what kind of thing they describe:
.socket: communication sockets
.device: hardware devices
.mount: mount points
.swap: swap files or partitions
.target: only dependencies, like Debian metapackages
.path: inotify monitoring of paths
.timer: cron-like activation
.slice: group processes for common resource management
.scope: group processes for common resource management
System unit files can be installed in:
/lib/systemd/system/: for units provided by packaged software
/run/systemd/system/: runtime-generated units
/etc/systemd/system/: for units provided by systemd administrators
Unit files in
/etc/ override unit files in
/lib/. Note that while Debian
/lib/, other distributions may use
If there is a directory with the same name as the unit file plus a
*.conf it contains is parsed after the unit, and can be used to add
or override configuration options.
/lib/systemd/system/beep.service.d/foo.confcan be used to tweak the contents of
/lib/systemd/system/beep.service, so it is possible for a package to distribute a tweak to the configuration of another package.
/etc/systemd/system/beep.service.d/foo.confcan be used to tweak the contents of
/lib/systemd/system/beep.service, so it is possible a system administrator to extend a packaged unit without needing to replace it entirely.
unitname.requires/ directory can be used to
Requires= dependencies on other units, by placing
symlinks to other units in them.