systemd is a system and service manager, which is after the Linux kernel itself the most import piece of software in Ubuntu (and the vast majority of other Linux distributions). systemd is responsible for starting, monitoring and administrating services at boot time as well as the running system. systemd is started as the very first process, thus has the PID 1.
As systemd is a fundamental part of the system, Ubuntu and its flavors come always with systemd preinstalled and preconfigured.
The basic building blocks for starting other services and controlling the systemd are units. Units are plain text files which typically consist of a number (commonly three) of section and each section holds a number of directives. The directives basically tell systemd what to do.
systemd has a number of different unit types, each one designated for a specific purpose. The type of unit is identified by the file name’s suffix. The various unit types are:
- .service - a service unit
- .timer - a timer unit
- .path - a path unit
- .mount - a mount unit
- .automount a automount unit
- .socket - a socket unit
- .device - a device unit
- .swap - a swap unit
- .target - a target unit
- .slice - a slice unit
- .scope - a scope unit
The most common units a user may get in touch with are service units and timer units. The former are used to start (and possibly monitor) services while the latter can be used a execute a program or script at a certain time or periodically.
systemd units and user units
systemd distinguishes between system units and user units. Each type of unit listed above can either be a system unit or a service unit. The difference is that system units are run by the system, e.g. at boot time, independent of which users will use the system, while user units are run once the users logs in. Each user can setup its own user units.
paths to units
For Ubuntu, system units are typically stored in one of the following to directories:
- /lib/systemd/system: units which are shipped with Ubuntu and units which are setup when installing further packages. These units are typically meant to be edits by the administrator or a user.
- ** /etc/systemd/system: this is the path where systemd units created by the administrator are stored.
User units are typically store in one of the following four directories:
- /usr/lib/systemd/user: directory for user units which are shipped with Ubuntu.
- /etc/systemd/user: this is the path where user units are stored creared by the administrator of the system.
- ~/.local/share/systemd/user: in the directory units are stored from packages installed for the specific user only.
- ~/.config/systemd/user: this is the path where units created by the user are stored.
systemctl is a central tool of system to interact with system. With
systemctl, the status of units can be checked, units can be started, stopped, deactivated etc. Furthermore,
systemctl can restart, poweroff or hibernate the system.
systemd comes with a logging demon named journald. Like systemd, it is part of every Ubuntu installation. All actions, errors etc. are logged into a centralized journal.
The journal can be queried by the journalctl tool.
further systemd tools
systemd comes with even more tools. Some of them are:
- systemd-analyze: tool to analyze to boot process
- systemd-blame: tool showing which unit consumes how much time while the boot process
- systemd-inhibit: inhibit that the systems can be shut down while certain units / processes are still running.
Ubuntu and systemd - a short history
Prior to systemd, Ubuntu used Upstart to control the boot process. Ubuntu 14.04 LTS “Trusty Tahr” was the last Ubuntu release which relied fully on Upstart, starting with Ubuntu 14.10 “Utopic Unicorn” the transitioning to systemd began. Ubuntu 15.04 “Vivid Vervet” was already mostly using systemd. The last Ubuntu release which used a few parts from Upstart was Ubuntu 16.04 LTS " Xenial Xerus". Since then all Ubuntu release make full use of systemd.