Skip to main content...
Linux + Bash Scripting
20 min

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.

A minimal service unit
# /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.target
Managing it
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
systemctl status myapp
journalctl -u myapp -f     # follow its logs

Targets 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 .service describing 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?

We use cookies

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Learn more

    Day 10: systemd — units, services, targets | RBTechIconX