Systemd Unit Types

systemd

I’m catching up on my systemd knowledge, this is almost a note to myself – a summary of the systemd unit types (yes, it’s a lot more than just startup scripts!).

How To Tell a systemd Unit Type

The quickest way to determine a systemd unit type is to just look at the last part of the unit file. For instance, if I list systemd units in /lib/systemd/system directory, I’ll find quite a mix. Here’s a fragment:

-rw-r--r--  1 root  1196 Jan 29 18:07 systemd-time-wait-sync.service
-rw-r--r-- 1 root 659 Jan 29 18:07 systemd-tmpfiles-clean.service
-rw-r--r-- 1 root 490 Feb 14 2019 systemd-tmpfiles-clean.timer
-rw-r--r-- 1 root 732 Jan 29 18:07 systemd-tmpfiles-setup-dev.service
-rw-r--r-- 1 root 772 Jan 29 18:07 systemd-tmpfiles-setup.service
-rw-r--r-- 1 root 635 Feb 14 2019 systemd-udevd-control.socket
-rw-r--r-- 1 root 610 Feb 14 2019 systemd-udevd-kernel.socket

I have highlighted the last part of each filename, and it shows the type of a particular unit: service, timer or socket (there’s more types, see below).

Types of systemd Units

Here are the systemd unit types I’ve come across so far. They must be the most common ones:

  • service: thats the one you’ve probably heard about, it’s a unit type for configuring and managing a software service (startup/shutdown) just like init scripts used to do – but in a far more flexible way
  • device – anything and everything for managing device files – stuff like operating files in /dev filesystem, etc
  • mount – Systemd style of managing filesystem mounts – for now these are mostly internal OS use filesystems of special types. The more traditional filesystems like / or /var are still managed in /etc/fstab
  • timer – scheduling system for running low-level tasks like OS self-healing and maintenance – this is where mdcheck (software RAID arrays) runs and how apt/yum repos are updated.
  • target – similar to milestones in Solaris 10, this is a boot management mechanism where you create these targets with meaningful names which become logical points of alignment for system initialisation and startup. There are targets for printing, rebooting, system update or multi-user mode – so other Systemd units can be depedencies and dedepdants for such targets.

See Also