Gist: Systemd daemon service
A sample Systemd service file for a daemon (web server) and useful commands.
Last updated on: 2024-12-27
Setup your unit file
[Unit] Description=Website After=network.target [Service] Type=simple Restart=always User=root Group=root WorkingDirectory=/var/<SERVICE_NAME>/ ExecStart=/usr/local/bin/<SERVICE_NAME> [Install] WantedBy=multi-user.target
Note: You probably want to use another user than root.
Enable the service
systemctl enable <SERVICE_NAME>
Start the service
systemctl start <SERVICE_NAME>
Check status
systemctl status <SERVICE_NAME>
Check logs
journalctl -u <SERVICE_NAME>
Follow logs
journalctl -u <SERVICE_NAME> -f