System States
A server running in a data center needs different services than a developer's laptop with a graphical desktop. Linux has always had the concept of "system states" — defined configurations of which services are running. In SysV init, these were called runlevels (numbered 0 through 6). In systemd, they are called Targets.
A Target Unit (.target) is a unit file that does nothing by itself. Its only purpose is to act as a synchronization point — a named group that other units can declare themselves part of, or that can declare dependencies on other units.
Common targets and their SysV equivalents:
| Target | SysV Runlevel | Description |
|---|---|---|
poweroff.target |
0 | Shut down the system |
rescue.target |
1 | Single-user mode, minimal services |
multi-user.target |
3 | Full multi-user, no GUI (standard for servers) |
graphical.target |
5 | Multi-user with graphical desktop |
reboot.target |
6 | Reboot the system |
How targets work in practice:
When your system boots, the kernel starts systemd, which reads the default target (usually graphical.target on desktops, multi-user.target on servers). Systemd then tries to activate that target. Because graphical.target has Requires=multi-user.target, it first activates multi-user.target. Because multi-user.target has Wants= pointing to dozens of services, all those services start in parallel.
Your service's WantedBy=multi-user.target in the [Install] section means: "when I am enabled, add me to the list of things that multi-user.target wants." Running systemctl enable myservice creates a symlink in /etc/systemd/system/multi-user.target.wants/myservice.service — that's the entire mechanism.
Checking and changing the default target: systemctl get-default reports which target the system boots into; systemctl set-default changes that persistently (e.g., switching a server to boot into text mode instead of a graphical desktop); and systemctl isolate switches to a target immediately, without a reboot.
isolate is powerful and dangerous: it stops all units not required by the target and starts all units that are. Use it carefully.