Skip to content
linuxsystem-management

systemd Unit

systemd-unitlinuxservices
Plain English

A systemd unit is a small text file that tells Linux how to run and look after a program: when to start it, as which user, and what to do if it crashes.

Technical Definition

Unit files live in /usr/lib/systemd/system (packages) and /etc/systemd/system (yours, which win).

  • Types: .service, .timer, .socket, .mount, .target.
  • [Unit] Description, After; [Service] ExecStart, User, Restart=on-failure; [Install] WantedBy.
  • systemctl daemon-reload after edits; systemctl edit for drop-in overrides.
  • systemctl cat name shows the effective file.

Source: systemd.unit(5)

systemd Unit in practice

[Unit]
Description=BNLC web

[Service]
User=student
ExecStart=/usr/bin/python3 -m http.server 8090
Restart=on-failure

[Install]
WantedBy=multi-user.target
In the Wild

Writing your own unit is how a script becomes a real service that starts at boot and restarts itself. BNLC lesson 8.1.