Chapter Eight

systemd and Services

The init system that owns PID 1, starts every service in dependency order, and replaced a directory of shell scripts with declarative unit files.

6 topics

PID 1 is the first userspace process the kernel starts and the ancestor of everything else on the machine; it brings the system up and reaps the orphaned children nothing else will. On every current Debian and Ubuntu release that PID 1 is systemd, which starts units in parallel based on their dependencies, supervises long-running services, and reaches well past boot into logging, timers, mounts, and login sessions.

This chapter is the one that pays off every time a service will not start. It begins with what systemd replaced and why, then teaches the unit files that describe services and the systemctl front door that drives them. From there it covers the targets that decide what a server boots into, the timers that retire most cron jobs, and the journal that holds every line those services ever logged.

How systemd brings the system up
systemdPID 1
basic.targetearly bring-up
multi-user.targetthe server state
servicesWants + After

Topics in This Chapter

Topic 40
init and systemd
What PID 1 actually does, how systemd's declarative dependency-ordered units replaced SysV's sequential shell scripts, and why boot got faster and supervision got built in. The single front door for the whole system.
systemdPID 1
Topic 41
Unit Files
The declarative .service file and its siblings — sockets, mounts, targets — plus the [Unit], [Service], and [Install] sections, the right Type=, and editing through drop-in overrides instead of vendor files in /lib that updates overwrite.
UnitsConfig
Topic 42
Managing Services
Driving units with systemctl: the difference between start (now) and enable (at boot), reading active and failed states with status, and running daemon-reload and systemctl edit after a unit changes on disk.
systemctlOps
Topic 43
Targets and Boot
Targets as the successors to runlevels — multi-user.target for servers, graphical and rescue states — set-default for what the box boots into, and systemd-analyze blame and critical-chain for finding the real bottleneck.
BootTargets
Topic 44
Timers
The modern alternative to cron: a .timer unit firing a .service unit on a calendar or monotonic schedule, with logging, missed-run catch-up via Persistent=true, and RandomizedDelaySec to spread the top-of-the-hour load cron cannot.
SchedulingTimers
Topic 45
journald
The structured binary journal systemd-journald keeps for the kernel and every unit, queried by unit, time, priority, and boot with journalctl, plus the volatile-versus-persistent storage choice and how it coexists with rsyslog.
Logsjournald