Manage Services with systemctl
Most Linux systems use systemd to run background services, such as web servers, databases and SSH. systemctl controls the services, and journalctl shows their log messages.
Checking a service
systemctl status apache2Shows whether the Apache web server is running, plus its latest log lines. Press q to exit.
systemctl list-units --type=service --state=runningLists every service that is running.
systemctl --failedLists services that have failed.
Starting and stopping
sudo systemctl restart apache2Stops and starts a service. Use start and stop to do just one.
sudo systemctl reload apache2Reloads the settings without stopping the service, if it supports it.
sudo systemctl enable --now apache2Starts the service now and every time the computer boots. Use disable to stop it starting at boot.
Reading logs with journalctl
journalctl -u apache2Shows the log messages for one service.
journalctl -u apache2 -fFollows the log live, showing new messages as they arrive. Press Ctrl + C to stop.
journalctl --since "1 hour ago"Shows everything logged in the last hour.
journalctl -b -p errShows only errors since the computer last started.
Tip: Add sudo to see log messages from every service.
Quick reference
| Option | Meaning |
|---|---|
status | Is the service running? |
start / stop | Start or stop it now |
restart / reload | Restart, or reload its settings |
enable / disable | Start it at boot, or not |
--failed | List failed services |
journalctl -u name | Logs for one service |
journalctl -f | Follow the log live |