linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Processes & resources/systemd-unit-types

kb/processes ── Processes & resources ── intermediate

systemd unit types

A unit is a resource managed by systemd. The file extension equals the type: `.service` (daemon), `.socket` (lazy start on a socket), `.timer`, `.mount`, `.path`, `.slice`/`.scope` (cgroups), `.target` (a group).

view as markdownaka: unit-file-types, unit-extensions, systemd-units

Where unit files live

Three directories, priority bottom to top (lower wins):

/usr/lib/systemd/system/   ← from packages (canonical, /lib/systemd/system - symlink)
/run/systemd/system/       ← runtime, generated (systemd-fstab-generator and others)
/etc/systemd/system/       ← local edits by the SysAdmin, overrides

If a file with the same name exists in /etc/ and in /usr/lib/, the /etc/ one wins entirely. For a partial edit, use a drop-in (see systemd-drop-ins).

Full list of types

ExtensionWho writes itPurpose
.serviceSysAdminOrdinary daemon (sshd, nginx, postgres)
.socketSysAdminListen on a socket, activate a service on demand
.timerSysAdminCron replacement (see systemd-timers)
.mountSysAdmin / autoMount point (generated from mount-and-fstab)
.automountSysAdminLazy mount: mounts on first access
.swapSysAdmin / autoSwap device or file
.targetSysAdmin / distGroup of units (see systemd-targets)
.pathSysAdminTrigger a service on a file/directory change
.sliceSysAdmin / autoA node in the cgroups hierarchy for limits
.scopesystemdExternally created process group (sessions)
.deviceudev → systemdA /dev/* appeared, automatic, usually no file

.service: the most common

Manages a daemon. The key directives are Type= and ExecStart=.

ini
# /etc/systemd/system/myapp.service
[Unit]
Description=My App
After=network-online.target postgresql.service
Requires=postgresql.service
[Service]
Type=simple
ExecStart=/usr/local/bin/myapp
Restart=on-failure
User=myapp
[Install]
WantedBy=multi-user.target

Type=simple is the most common. The binary does not fork. For the alternatives, see systemd.

.socket: socket activation

The core idea: systemd listens on the socket INSTEAD of the service. On the first connection it starts the paired .service and hands it the already open fd.

ini
# /etc/systemd/system/myapp.socket
[Unit]
Description=My App socket
[Socket]
ListenStream=8080
Accept=no               # one service for all connections (the default)
[Install]
WantedBy=sockets.target

Why:

  • Lazy start means the service uses no RAM until someone connects.
  • Parallel boot lets clients write to the socket BEFORE the service has actually started; systemd buffers it.
  • Zero-downtime restart means a service restart does not drop connections.

A real-world example: cups.socket, pcscd.socket, docker.socket.

.timer: a schedule

See systemd-timers. The paired .service runs on the schedule.

.mount: a mount point

The file name is the mount point with / replaced by -. /var/data → var-data.mount.

ini
# /etc/systemd/system/var-data.mount
[Unit]
Description=Data partition
[Mount]
What=/dev/disk/by-uuid/abc-123
Where=/var/data
Type=ext4
Options=defaults,noatime
[Install]
WantedBy=multi-user.target

In practice you rarely write .mount units by hand. systemd-fstab-generator parses mount-and-fstab and creates them in /run/systemd/system/. Your own unit is needed when you require specific Requires=/After=.

.automount: mount on demand

An .automount paired with a .mount. The filesystem itself is not mounted at boot, only on the first access to the directory. For rarely used NFS or removable disks.

ini
# /etc/systemd/system/mnt-nfs.automount
[Unit]
Description=NFS automount
[Automount]
Where=/mnt/nfs
TimeoutIdleSec=600       # unmount after 10 min idle
[Install]
WantedBy=multi-user.target

.path: react to a file

Triggers the paired service when a file appears or changes. Inotify under the hood.

ini
# /etc/systemd/system/upload-watcher.path
[Path]
PathExistsGlob=/var/uploads/*.zip
Unit=process-upload.service
[Install]
WantedBy=multi-user.target

This works only if the paired service is Type=oneshot (or simply short-lived).

.slice and .scope: cgroup nodes

  • .slice is a hierarchical container that groups services under shared limits. The system defaults: system.slice (daemons), user.slice (users), machine.slice (VMs and containers).
  • .scope is created programmatically by systemd for externally launched process groups: SSH sessions (session-1.scope), systemd-run, containers from Docker or Podman.

You write your own slice to pin a limit on a group of services:

ini
# /etc/systemd/system/heavy.slice
[Slice]
CPUQuota=200%
MemoryMax=4G

And in the services: Slice=heavy.slice. See cgroups.

Debug: what is on the system

bash
systemctl list-unit-files                       # ALL installed units
systemctl list-unit-files --type=service        # services only
systemctl list-units --type=socket              # active sockets
systemctl list-units --type=mount --all         # all mount units, including stopped ones
systemctl cat docker.socket                     # the full contents of a unit
systemctl show -p TriggeredBy nginx.service     # what triggers this service

States in the STATE column:

  • enabled means there is a symlink in *.target.wants/ (starts at boot)
  • disabled means there is no symlink
  • static means there is no [Install] section, you cannot enable it, it is pulled in only through dependencies
  • masked means /etc/systemd/system/<unit> → /dev/null (cannot be started at all)

§ команды

bash
systemctl list-unit-files --type=timer --state=enabled

All enabled timers, an overview of what actually starts on a schedule

bash
systemctl cat ssh.socket

The full resolved unit file with applied drop-ins

bash
systemctl show -p Type,ExecStart,User nginx.service

Specific directives of a unit without printing the whole file

bash
sudo systemctl mask telnet.socket

Hard-disable a unit, a symlink to /dev/null, it cannot be started at all

bash
systemd-analyze verify /etc/systemd/system/myapp.service

Check a unit file before daemon-reload, syntax, deps, errors

§ см. также

  • systemdsystemd: the init system and service managersystemd is the Linux init system: PID 1 that starts everything else, tracks dependencies, restarts what crashes, and collects the logs.
  • systemd-targetssystemd targets: runlevels the new wayA target is a `.target` unit that describes a desired system state as a set of dependencies. It replaces SystemV runlevels: `multi-user.target` ≈ runlevel 3, `graphical.target` ≈ runlevel 5.
  • systemd-timerssystemd timers as a cron replacementA systemd timer is a `.timer` unit that runs a paired `.service` on a schedule or after an interval from an event (boot, last run). It replaces cron with logs in [[cmd-journalctl]] and dependencies.
  • systemd-drop-inssystemd drop-ins: override without editing the originalA drop-in is a `.conf` file in a `<unit>.d/` directory that merges into the unit file. It overrides any directive of a unit **without editing the original file** from the package.
  • cgroupscgroups (v2)cgroups v2 is a hierarchical virtual FS under `/sys/fs/cgroup` that the kernel uses to limit CPU, memory, and I/O for processes. Docker, k8s, and systemd write here.
  • mount-and-fstabmount and /etc/fstab: attaching filesystems`mount` attaches a block device or filesystem to a mount point in the tree. `/etc/fstab` is the list of what to mount at boot.
  • cmd-systemctlsystemctl: managing systemd services`systemctl` is the main CLI for managing systemd units: services, timers, mounts, and sockets. It replaces SysV init and `service` on modern distros.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies