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:

[Unit]
Description=Network Time Service

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

[Install]
WantedBy=multi-user.target

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.

Targets

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 rescue.target, 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 multi-user.target unit, which can be set as the standard with this link:

ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

If, at a later point, you do want the graphical login interface to be a standard part of boot-up, you can set graphical.target 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:

systemd.unit=multi-user.target

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

systemctl isolate rescue.target

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 emergency.target to go to emergency mode, where only the process for the input prompt runs, along with the kernel threads.

Next: Dependencies

Print Version | Permalink: http://h-online.com/-1570630
  • 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