Boot and service managers
How a host gets from power-on to running services, and why a service started by hand differs from a managed one.
From power-on to PID 1
A host boots in stages. Firmware finds a boot loader. The boot loader loads a kernel and an initial RAM filesystem. The kernel initialises hardware, mounts the root filesystem, and starts exactly one user-space program, init, as PID 1. Every other process on the system descends from it. On almost every current distribution init is systemd. Its job is to bring the system to a goal state, called a target, by starting units in dependency order, and to supervise them afterwards.
You rarely debug firmware or the kernel in day-to-day operations. You debug the last stage constantly. When a host "comes back from a reboot without the app", the question is almost always about how the service manager was told to run it.
A unit is a contract
A service unit describes how to run a program. The parts that matter most in incidents:
[Unit]
Description=Waybill API
After=network-online.target
Wants=network-online.target
[Service]
User=waybill
WorkingDirectory=/srv/waybill
EnvironmentFile=/etc/waybill/env
ExecStart=/srv/waybill/bin/server --config /etc/waybill/config.yaml
Restart=on-failure
[Install]
WantedBy=multi-user.target
Each line replaces something a human shell would have provided implicitly. User= replaces "whoever is logged in". WorkingDirectory= replaces "wherever I cd'd". EnvironmentFile= replaces "what my profile exported", and ExecStart= needs an absolute path because there is no interactive PATH. [Install] says which target pulls the unit in at boot, but only once you enable it.
Why "works by hand" fails under the manager
Starting a program from your shell gives it your identity, your directory, your environment, and your terminal. Starting it from the manager gives it whatever the unit says, and nothing else. List the differences before you change anything:
- Identity. Can user
waybillread the config and write the data directory? - Directory. Does the program open relative paths?
- Environment. Which variables did your shell have that the unit lacks?
- Ordering. Does it need the network or a mount that is not ready yet?
- Persistence. Is it enabled, or only started?
systemctl show waybill -p User -p WorkingDirectory -p Environment prints what the manager will actually use. systemctl cat waybill shows the unit together with any drop-ins.
Change units the maintainable way
Vendor units live in /usr/lib/systemd/system and belong to the package. Local units and overrides go in /etc/systemd/system. systemctl edit waybill creates a drop-in containing only your change, which survives package upgrades and documents intent. After any edit, systemctl daemon-reload makes systemd re-read the definitions. Then restart the unit and verify its effect, not just its status. A unit can be "active (running)" while the program inside it is listening on the wrong address.
Restart policy is not a fix
Restart=on-failure keeps a service available through transient crashes. It also hides a crash loop until the start limit is hit and systemd gives up. If a service is restarting, read why in journalctl -u waybill -b. Treat a high restart count as an open incident, not a solved one.
When an edit does not take effect
Two things stand between a changed unit file and a changed process. First, systemd runs the definition it loaded, not the file on disk. Until systemctl daemon-reload, a restart reuses the old definition, and systemctl status warns that the unit file changed on disk. Second, a setting can come from several places. Environment= lines are applied first and EnvironmentFile= files after them, so a variable set in both takes the file's value. Drop-ins in /etc/systemd/system/<unit>.d/ override the main file. systemctl cat <unit> shows every piece in order, and systemctl show -p Environment <unit> shows what was loaded. After the change, check the process itself: the port it listens on, or the address it logs at startup. "active (running)" only means a process exists.
Key terms
- init
- PID 1, the first user-space process. On most current distributions it is systemd, which starts and supervises everything else.
- Unit
- A systemd object (service, socket, timer, mount, and others) described by a unit file.
- Enable versus start
startruns the unit now.enablelinks it into a target so it starts at boot. You usually want both.- Restart policy
- Whether the manager restarts a service after it exits, for example
Restart=on-failure.
Read further
- How Linux Works, 3rd edition, Ch. 5, "How the Linux Kernel Boots", and Ch. 6, "How User Space Starts" (Purchase)
In Ch. 5, only the overview of the boot sequence. In Ch. 6, read the systemd sections in full. Note unit types, dependencies, and the difference between a unit file and its runtime state. - UNIX and Linux System Administration Handbook, 5th edition, Ch. 2, "Booting and System Management Daemons" (Purchase)
The systemd sections, especiallysystemctlsubcommands, unit file locations and precedence, and the warning about editing vendor unit files instead of using overrides.