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 changesUnit file
[Unit]
Description=My service
After=network.target
[Service]
ExecStart=/usr/bin/my-service
Restart=on-failure
User=www-data
[Install]
WantedBy=multi-user.targetLogs
journalctl -u nginx -f shows live logs, journalctl --since today since today, journalctl -p err only errors.
Common issues
Failed to start: checksystemctl status+journalctl -xe.- Port in use:
ss -tlnp. - Permissions: check the User in the unit.
See also: System Administration.