systemd is the service manager used by Ubuntu, Debian, and most modern Linux distributions to start, stop, restart, and monitor background services (Nginx, MySQL, SSH, Docker, and more). Understanding systemctl is a core Linux administration skill.
Checking a Service's Status
sudo systemctl status nginx
This shows whether it's active, when it started, and recent log output.
Starting, Stopping, and Restarting a Service
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
Reloading Configuration Without Downtime
For services that support it (like Nginx), reload applies config changes without dropping active connections:
sudo systemctl reload nginx
Enabling a Service to Start on Boot
sudo systemctl enable nginx
Enable and start in one command:
sudo systemctl enable --now nginx
Disabling a Service from Starting on Boot
sudo systemctl disable nginx
Checking If a Service Is Enabled
sudo systemctl is-enabled nginx
Listing All Running Services
systemctl list-units --type=service --state=running
Finding Failed Services
sudo systemctl --failed
This is especially useful right after a reboot to catch anything that didn't start correctly.
Viewing a Service's Logs
sudo journalctl -u nginx
Follow logs live:
sudo journalctl -u nginx -f
Show only the last hour:
sudo journalctl -u nginx --since "1 hour ago"
Creating a Custom systemd Service
Useful for running your own application as a managed background service:
sudo nano /etc/systemd/system/myapp.service
[Unit]
Description=My Application
After=network.target
[Service]
ExecStart=/usr/bin/node /opt/myapp/index.js
Restart=always
User=deploy
WorkingDirectory=/opt/myapp
[Install]
WantedBy=multi-user.target
Reload systemd and start it:
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
Common Errors
"Unit not found" — check the exact service name with systemctl list-units --type=service.
Custom service fails to start — check logs with journalctl -u myapp -n 50 and verify the ExecStart path is correct and executable.
Best Practices
- Always check
systemctl statusafter making a config change, before assuming it worked - Use
reloadinstead ofrestartwhen available, to avoid dropping connections - Set
Restart=alwayson custom services so they recover automatically from crashes
FAQ
What's the difference between restart and reload?restart fully stops and starts the service (brief downtime); reload re-reads configuration without interrupting active connections, when the service supports it.
Related Articles
- How to Read and Analyze Linux Logs with journalctl
- How to Reboot a Linux VPS Safely
- How to Schedule Tasks with Cron on a Linux VPS
