Master Systemd Service Management with systemctl: Start, Stop, Restart & Enable
This guide explains how to use systemd’s systemctl command to start, stop, restart, reload, check status, and configure boot-time enablement for services such as Nginx, along with journalctl techniques for viewing logs and troubleshooting service failures on Linux systems.
1. What is Systemd?
Systemd is the first process (PID 1) started by Linux after boot, responsible for launching and managing all other processes. Although it is sometimes criticized for being too broad, it standardizes service management across Linux distributions.
2. Core command: systemctl
The systemctl utility is the Swiss‑army‑knife for managing services. For example, to control the nginx service you can use:
Start the service: sudo systemctl start nginx Stop the service: sudo systemctl stop nginx Restart the service: sudo systemctl restart nginx Reload configuration without interrupting the service: sudo systemctl reload nginx Check the service status: sudo systemctl status nginx (green “active (running)” means the service is up, red “failed” indicates a problem).
Two additional useful commands are:
systemctl list-units --type=service --state=running
systemctl list-unit-files --type=service | head3. Managing boot‑time enablement
Enable a service to start at boot: sudo systemctl enable nginx Disable a service from starting at boot: sudo systemctl disable nginx Check whether a service is enabled:
sudo systemctl is-enabled nginx4. Viewing system logs with journalctl
If a service fails to start, you can inspect its logs using journalctl:
Show all logs: journalctl Show logs for a specific service: journalctl -u nginx Follow new log entries in real time (similar to tail -f): journalctl -u nginx -f Show error‑level logs from the current boot: journalctl -b -p err Show the last 200 lines without paging: journalctl -u nginx -n 200 --no-pager Show logs since a specific time, e.g., one hour ago: journalctl -u nginx --since "1 hour ago" After modifying a service’s configuration or unit file, reload the daemon and restart the service:
sudo systemctl daemon-reload
sudo systemctl restart nginxMastering systemctl and journalctl gives you essential server‑operation skills.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ubuntu
Focused on Ubuntu/Linux tech sharing, offering the latest news, practical tools, beginner tutorials, and problem solutions. Connecting open-source enthusiasts to build a Linux learning community. Join our QQ group or channel for discussion!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
