systemd jots

This post was written by eli on November 11, 2015
Posted Under: Linux,Software

I not an expert on this

These are just my what-on-earth-is-going-on-here notes as I tried to understand how my Debian 8.2 (“Jessie”) machine boots up. Conclusion: It’s a mess. More specifically, it’s a weird mix between good-old SystemV init scripts and a nasty flavor of upstart. And they say it’s here to stay. Maybe. But I doubt those init.d scripts will remain for long.

General notes

  • systemctl is the Swiss knife. Most notable commands: systemctl {halt, poweroff, reboot}
  • Also: systemctl status (for a general view, with PIDs for jobs) or with the name of a service to get more specific info
  • For analysis of what’s going on: systemctl {cat, list-dependencies}
  • Reload configuration files (after making changes): systemctl daemon-reload
  • LSB stands for Linux Standard Base. In systemd context, it’s the standard Linux services
  • There are several special units: man systemd.special
  • An example for a service definition file (for SSH): /etc/systemd/system/sshd.service. There aren’t so many of these.

The general view

My atd daemon didn’t kick off, so I got this:

(the numbers are process IDs, which is quite nice, but don’t kill them directly — use systemctl for that too)

$ systemctl status
 diskless
    State: degraded
     Jobs: 0 queued
   Failed: 1 units
    Since: Wed 2015-11-11 14:45:42 IST; 4min 39s ago
   CGroup: /
           ├─1 /sbin/init text
           └─system.slice
             ├─dbus.service
             │ └─352 /usr/bin/dbus-daemon --system --address=systemd: --nofork -
             ├─cron.service
             │ └─345 /usr/sbin/cron -f
             ├─nfs-common.service
             │ ├─299 /sbin/rpc.statd
             │ └─342 /usr/sbin/rpc.idmapd
             ├─exim4.service
             │ └─632 /usr/sbin/exim4 -bd -q30m
             ├─systemd-journald.service
             │ └─127 /lib/systemd/systemd-journald
             ├─ssh.service
             │ ├─347 /usr/sbin/sshd -D
             │ ├─639 sshd: fake [priv]
             │ ├─641 sshd: fake@pts/0
             │ ├─642 -bash
             │ ├─666 systemctl status
             │ └─667 systemctl status
             ├─systemd-logind.service
             │ └─349 /lib/systemd/systemd-logind
             ├─system-getty.slice
             │ └─getty@tty1.service
             │   └─402 /sbin/agetty --noclear tty1 linux
             ├─systemd-udevd.service
             │ └─139 /lib/systemd/systemd-udevd
             ├─rpcbind.service
             │ └─266 /sbin/rpcbind -w
             ├─irqbalance.service
             │ └─370 /usr/sbin/irqbalance --pid=/var/run/irqbalance.pid
             └─rsyslog.service
               └─398 /usr/sbin/rsyslogd -n

Networking service who-does-what

What’s about the networking service? Just

$ systemctl

(not necessarily as root) listed all known services (including those that didn’t start), and among others

  networking.service                 loaded active exited    LSB: Raise network interfaces.

so let’s take a closer look on the networking service:

$ systemctl status networking.service
 networking.service - LSB: Raise network interfaces.
   Loaded: loaded (/etc/init.d/networking)
  Drop-In: /run/systemd/generator/networking.service.d
           └─50-insserv.conf-$network.conf
        /lib/systemd/system/networking.service.d
           └─network-pre.conf
   Active: active (exited) since Wed 2015-11-11 11:56:35 IST; 1h 16min ago
  Process: 242 ExecStart=/etc/init.d/networking start (code=exited, status=0/SUCCESS)

OK, let’s start with the drop-in file:

$ cat /run/systemd/generator/networking.service.d/50-insserv.conf-\$network.conf
# Automatically generated by systemd-insserv-generator

[Unit]
Wants=network.target
Before=network.target

Not really informative. Note that /run is a tmpfs, so no doubt the file was automatically generated. So what about

$ cat /lib/systemd/system/networking.service.d/network-pre.conf
[Unit]
After=network-pre.target

Even more internal mumbo-jumbo. So much for the drop-ins.

Now, why am I working so hard? There the “cat” command!

$ systemctl cat networking.service
# /run/systemd/generator.late/networking.service
# Automatically generated by systemd-sysv-generator

[Unit]
SourcePath=/etc/init.d/networking
Description=LSB: Raise network interfaces.
DefaultDependencies=no
Before=sysinit.target shutdown.target
After=mountkernfs.service local-fs.target urandom.service
Conflicts=shutdown.target

# /run/systemd/generator.late/networking.service
# Automatically generated by systemd-sysv-generator

[Unit]
SourcePath=/etc/init.d/networking
Description=LSB: Raise network interfaces.
DefaultDependencies=no
Before=sysinit.target shutdown.target
After=mountkernfs.service local-fs.target urandom.service
Conflicts=shutdown.target

[Service]
Type=forking
Restart=no
TimeoutSec=0
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SysVStartPriority=12
ExecStart=/etc/init.d/networking start
ExecStop=/etc/init.d/networking stop
ExecReload=/etc/init.d/networking reload

# /run/systemd/generator/networking.service.d/50-insserv.conf-$network.conf
# Automatically generated by systemd-insserv-generator

[Unit]
Wants=network.target
Before=network.target

# /lib/systemd/system/networking.service.d/network-pre.conf
[Unit]
After=network-pre.target

Say what? The actual networking.service was generated on the fly? Based on what?

Say what II? /etc/init.d/networking??? Really? Besides, what’s all those /etc/rcN.d/ directories? Are they used for something?

OK, so it goes like this: According to systemd-sysv-generator’s man page (the program that generated these service files) scans through /etc/init.d/* and reads through their LSB headers. It probably also scanned /etc/rcS.d, where it found S12networking symlinking to ../init.d/networking. That’s where it got the SysVStartPriority=12 part, I suppose.

So this is how systemd emulated SystemV.

Netwoking service: What actually happens

  • Systemd calls /etc/init.d/networking start (systemctl status networking.service supplied that info)
  • /etc/init.d/networking runs /etc/default/networking (if it exists), which allows overriding the parameters
  • Then calls “ifup -a”, unless CONFIGURE_INTERFACES has been set to “no”, and with due exclusions

References

Add a Comment

required, use real name
required, will not be published
optional, your blog address