systemd: Managing Services with systemctl

systemd is the init daemon of most Linux distributions. Services are described as units and managed with systemctl.

Essential commands

systemctl status nginx
systemctl start nginx
systemctl enable nginx      # start on boot
systemctl restart nginx
systemctl daemon-reload     # after unit changes

Unit file

[Unit]
Description=My service
After=network.target

[Service]
ExecStart=/usr/bin/my-service
Restart=on-failure
User=www-data

[Install]
WantedBy=multi-user.target

Logs

journalctl -u nginx -f shows live logs, journalctl --since today since today, journalctl -p err only errors.

Common issues

  • Failed to start: check systemctl status + journalctl -xe.
  • Port in use: ss -tlnp.
  • Permissions: check the User in the unit.

See also: System Administration.