In association with heise online

The back way

A central characteristic of systemd is its socket activation, which allows it to start background services in parallel without explicitly specifying any dependencies as soon as the basic system is set up and the local filesystems have been mounted. The clever aspect is that systemd itself creates the sockets that are used as communication pathways for the services that are to be launched, and then hands the sockets over to the services while launching.

The Syslog and D-Bus services are good examples to illustrate this concept. When it is started, D-Bus connects to the /dev/log socket and uses it to communicate with the log daemon so that this daemon can write status and error messages to the system log if required. Therefore, SysV-init distributions only launch D-Bus once the Syslog service is fully functional.

Systemd, on the other hand, creates /dev/log itself and then launches Syslog and D-Bus at the same time; any data sent to /dev/log by D-Bus before Syslog is ready will be sent to a buffer. Originally, systemd let the kernel handle buffering; in current systemd versions, the included "journal" log feature takes care of this task.

This allows systemd to start Bluetooth, Avahi and other services that communicate with the log daemon or D-Bus at the same time as Syslog and D-Bus. When Avahi expects a D-Bus response, the process automatically stops at that point and readily resumes as soon as the response arrives from the socket. Should D-Bus fail to start for any reason, systemd aborts the start of Bluetooth and Avahi after some time.


Zoom The socket activation may change the order in which the services confirm their start. Here, the Irqbalance daemon announces its start before D-Bus and Syslogd; the opposite happened during the next boot.
Apple uses the same principle in launchd, which was introduced with Mac OS X 10.4 and is also part of iOS; the init system is thought to be the main reason for the significantly faster starting times of recent Mac OS versions, because launching services in parallel makes more efficient use of the available CPU and I/O resources. In typical SysV-init distributions, on the other hand, services are launched in a fixed order – Bluetooth and Avahi are only launched once D-Bus, which is itself started after Syslog, is up and running. Even the co-dependent Bluetooth and Avahi only start in parallel in a few SysV-init distributions, for example in some versions of Debian and SUSE. The distributors specify the required dependency information in the headers of the init scripts.

On demand

Since systemd creates and maintains the socket, it can relaunch a crashed service without causing the programs that are connected to the socket to lose their connections. This makes it easier to update system components, because the kernel will buffer the client requests it receives from the socket during the restart, which simply allows the new service to take over where the old one left off.

Sockets can also be submitted to various programs. Systemd uses this option to log status messages even before the root filesystem has been mounted as writeable. For this purpose, it starts a minimal log service early on in the boot process; this service then simply writes all messages to the kernel log buffer. The minimal service is necessary because programs can only post messages if something is listening on /dev/log; the mini service will be shut down as soon as the actual Syslog server is ready to boot. The Syslog server takes over the socket and writes all previously submitted messages from the kernel log buffer to the hard disk; no messages will be lost, which enables systems to log events from the first moment they begin to boot.

Next: Units and targets

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