Day 10: systemd — units, services, targets
systemd: the modern init system
systemd is PID 1 — the first process the kernel starts, responsible for bringing up (and supervising) every other service. Services are defined as unit files; a .service unit describes how to start, stop, and restart a program, and what it depends on.
# /etc/systemd/system/myapp.service
[Unit]
Description=My Node app
After=network.target
[Service]
ExecStart=/usr/bin/node /opt/myapp/server.js
Restart=on-failure
User=appuser
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable --now myapp
systemctl status myapp
journalctl -u myapp -f # follow its logsTargets group units together (e.g. multi-user.target roughly means "normal multi-user boot, no GUI"). Just like SSH's sshd_config.d from Day 8, systemd supports drop-in overrides (systemctl edit myapp) so you can override one setting without touching the original unit file.
Key terms
- PID 1 / systemd
- The first process started by the kernel; supervises and manages all other services.
- Unit
- A systemd configuration object — most commonly a
.servicedescribing how to run a program. - Target
- A systemd grouping of units representing a system state, like multi-user.target.
What is systemd's role as PID 1?