Managing Services with systemd: Start, Auto-Start on Boot, and Read Logs
Use systemctl and journalctl to run services on your server: start and stop them, enable auto-start on boot, troubleshoot with logs, and write a minimal service unit.
Most modern Linux distributions (Ubuntu, Debian, CentOS, and others) use systemd to manage background services. Learn two commands, systemctl and journalctl, and you can start, stop, auto-start, and troubleshoot almost any service on your VPS.
The Basics: Start, Stop, Restart
We'll use Nginx as an example, but swap nginx for your own service name. These actions change the system, so they usually need sudo.
sudo systemctl start nginx # start it
sudo systemctl stop nginx # stop it
sudo systemctl restart nginx # stop, then start again
sudo systemctl reload nginx # re-read config without dropping connections (if supported)
After editing a config file, reach for reload first; fall back to restart only when the service doesn't support reloading.
Checking Status
systemctl status nginx
A few lines matter most: Active: active (running) means it's up; the word enabled or disabled at the end of the Loaded line tells you whether it starts on boot; and the last few log lines are shown right there, which is handy for debugging. Checking status normally doesn't need sudo.
Auto-Start on Boot: enable and disable
start only runs the service right now — it won't come back after a reboot. To have a service launch automatically at boot, use enable:
sudo systemctl enable nginx # start automatically on boot
sudo systemctl enable --now nginx # enable on boot AND start it now
sudo systemctl disable nginx # don't start on boot
systemctl is-enabled nginx # check whether it's set to auto-start
Keep the two ideas separate: enable controls whether it starts at boot, while start controls whether it's running right now.
Reading Logs: journalctl
systemd collects service logs in one place; read them with journalctl:
journalctl -u nginx # all logs for this service
journalctl -u nginx -n 50 # the last 50 lines
journalctl -u nginx -f # follow live (like tail -f)
journalctl -u nginx --since today # today's logs only
journalctl -u nginx -p err # errors only
When a service won't start, check status for the summary, then run journalctl -u <service> -n 50 to see recent entries — the reason is almost always in there.
Writing a Minimal Service Unit
To hand your own program over to systemd, create a .service file under /etc/systemd/system/, for example myapp.service:
[Unit]
Description=My App
After=network.target
[Service]
ExecStart=/usr/local/bin/myapp
Restart=on-failure
User=www-data
[Install]
WantedBy=multi-user.target
Use an absolute path in ExecStart, and Restart=on-failure will bring the program back if it crashes. Whenever you add or change a unit file, reload systemd before enabling it:
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
Summary
- One-off control: start / stop / restart / reload.
- Use status for a quick health check and journalctl -u <service> for the full logs.
- enable sets auto-start on boot, disable turns it off — independent of whether it's running now.
- For a custom service, drop in a .service file, then run daemon-reload followed by enable --now.