When you apt install postgresql on a Linux server and it’s simply running after the next reboot, systemd is why. It’s the first process the kernel starts, and everything else on the machine, from the database to the SSH daemon to the timer that rotates logs, is something it was told to manage. Each of those things is described by a unit: a short text file in an INI-like format that says what the thing is, how to run it, and when.
Where units live
Packages install theirs under /usr/lib/systemd/system/ (or /lib/systemd/system/ on some distributions). Yours go in /etc/systemd/system/, and a file there with the same name as a package’s unit wins. There’s also a per-user tree at ~/.config/systemd/user/ for things that should run as you, not as root.
Anatomy of a service
Here is a unit for a Bun app, the kind of thing I’d write to run an API on a small VPS:
[Unit]
Description=MetaMove API
After=network-online.target postgresql.service
Wants=network-online.target
[Service]
Type=simple
User=app
WorkingDirectory=/srv/metamove
EnvironmentFile=/etc/metamove.env
ExecStart=/usr/local/bin/bun run start
Restart=on-failure
RestartSec=3
[Install]
WantedBy=multi-user.targetThree sections, three questions.
[Unit]: what is this, and what has to come first? After= is about order: don’t start me until these have started. Wants= is a soft dependency: try to start these too, but don’t fail if they don’t. Requires= is the hard version, where their failure is your failure. Most services want After=network-online.target and nothing stronger.
[Service]: how do I run it? Type=simple means the process you launch is the service; it stays in the foreground and systemd watches it. User= runs it as an unprivileged account, which you should always do. ExecStart= needs an absolute path. Restart=on-failure with RestartSec=3 gives you a supervisor for free: crash, wait three seconds, start again. EnvironmentFile= keeps secrets out of the unit file itself.
[Install]: what does “enable” mean for me? WantedBy=multi-user.target says “when the system reaches the normal, booted, multi-user state, it wants me”. That line is what makes the service start at boot, once you enable it.
enable and start are different verbs
This is the one that bites everyone once.
sudo systemctl start metamove # run it now. Says nothing about the next boot.
sudo systemctl enable metamove # start it at boot. Says nothing about right now.
sudo systemctl enable --now metamove # both.enable creates a symlink in /etc/systemd/system/multi-user.target.wants/, which is how the WantedBy= line takes effect. disable removes it. stop and start only touch the running process. A service can be enabled and stopped, or running and disabled, and status shows you both at once:
● metamove.service - MetaMove API
Loaded: loaded (/etc/systemd/system/metamove.service; enabled; preset: enabled)
Active: active (running) since Mon 2026-11-09 09:00:12 PST; 2h 3min ago
Main PID: 1420 (bun)enabled is the boot answer. active (running) is the right-now answer.
The four commands that cover most days
systemctl status metamove # is it running, since when, and the last few log lines
sudo systemctl restart metamove # after a deploy
journalctl -u metamove -f # its logs, following. --since "10 min ago" also works
sudo systemctl daemon-reload # after editing any unit fileThat last one is the second thing that bites everyone. systemd reads unit files into memory. Edit one and restart the service, and you’ll get the old definition until you daemon-reload. There’s no error, only a one-line warning that the file changed on disk, and the restart goes ahead with the old definition.
Changing a package’s unit without editing it
Don’t edit the file under /usr/lib/systemd/system/; the next package upgrade will overwrite it. Instead:
sudo systemctl edit postgresqlThat opens an override file at /etc/systemd/system/postgresql.service.d/override.conf that holds only the keys you change, layered on top of the original. One rule to know: list-type keys like ExecStart= accumulate, so to replace one you clear it first:
[Service]
ExecStart=
ExecStart=/usr/local/bin/postgres -D /data/pgTimers instead of cron
A timer is a unit that starts another unit on a schedule. Two files, a .service that does the work and a .timer that says when:
[Timer]
OnCalendar=Mon *-*-* 03:00:00
Persistent=true
[Install]
WantedBy=timers.targetPersistent=true means if the machine was off at 03:00 on Monday, the job runs at the next boot instead of being skipped, which cron never did. systemctl list-timers shows every active timer, when it last ran, and when it’s next due, which is the overview cron never had either.
The mental model
A unit file is a contract: this is what I am, this is what I need first, this is how you run me, and this is when you should. start and stop act on now; enable and disable act on boot; daemon-reload tells systemd you changed the contract. Once those verbs are separate in your head, status and journalctl -u tell you everything else.