In association with heise online

Working with units

The system configuration files for creating units are in /lib/systemd/system/, but a file with the same name in /etc/systemd/system will take priority.

Unit definitions are usually much shorter than the classic sysvinit scripts. For example, a unit file for the service for synchronising network time via NTP is just a few lines long:

Description=Network Time Service

ExecStart=/usr/bin/ntpd -n -u ntp:ntp -g


All unit files include a section, starting with [Unit], with general settings and a short description. The [Service] section has service-specific tasks – for NTP, just the command-line to launch the service. If a specific command is required to end the program, you can set it using ExecStop=. This step is unnecessary for the NTP daemon, since, following Unix tradition, it can be ended with a simple "SIGTERM" signal, which tells systemd to end if no other command has been specified.

The [Install] section contains instructions for systemd to interpret during (de-)installation; the entry in the NTP example means that the time should be synchronised when the "Multi-User" target is activated.


The concept of "targets" units is similar to that of sysvinit's runlevels; indeed, for compatibility, systemd even understands runlevel names for equivalent targets. In Fedora 15, you can therefore enter the familiar single as a parameter in the kernel's boot-loader; systemd then activates, which provides a minimal interface comparable to single-user mode.

Along the same lines, 3 can be used to activate a multi-user mode – that is, to fully start the system without using the graphical login interface. In systemd, this mode is represented by the unit, which can be set as the standard with this link:

ln -sf /lib/systemd/system/ /etc/systemd/system/

If, at a later point, you do want the graphical login interface to be a standard part of boot-up, you can set as the standard target in the same way; this is the equivalent of runlevel 5 in older versions of Fedora and openSUSE. As an alternative to the old runlevels, you can also give the kernel the names of the target units to be started:

To activate a different target unit during operation, you can use systemctl's isolate command, which requires root privileges:

systemctl isolate

The change to the rescue target is interesting for administration tasks, since systemd now ends all user logins and background services so that only system services run, such as the one monitoring logical volumes (lvm2-monitor). Sometimes, even these services need to be ended for rebuilds; you can then use to go to emergency mode, where only the process for the input prompt runs, along with the kernel threads.

Next: Dependencies

Print Version | Permalink:
  • Twitter
  • Facebook
  • submit to slashdot
  • StumbleUpon
  • submit to reddit

  • July's Community Calendar

The H Open

The H Security

The H Developer

The H Internet Toolkit