Start, Stop & Restart systemd Services (Linux)
In this article
To start, stop, or restart a service on any systemd-powered Linux distribution (like Ubuntu, Debian, Fedora, or Arch), you use the systemctl command. The basic commands are sudo systemctl start SERVICE, sudo systemctl stop SERVICE, and sudo systemctl restart SERVICE. This guide walks you through each action, how to check status, and what to do when things don't work.
What You'll Need
- A Linux system using systemd (most modern distributions do). To verify, run
ps -p 1– if the output showssystemd, you're good. - Access to a terminal.
sudoprivileges (administrative rights) to control services.- The exact name of the service you want to manage. You can find it with
systemctl list-units --type=serviceor by checking the documentation of the software you installed.
Step-by-Step
- Identify the service name. Services are named like
nginx.service,ssh.service, ordocker.service. You can list all active services withsystemctl list-units --type=service. If you're unsure, trysystemctl statusto see a list of running services. - Check the current status. Before changing anything, see if the service is running, stopped, or failed. Run
systemctl status SERVICE(replaceSERVICEwith the actual name). The output shows whether it's active (running) or inactive (dead). - Start a service. Use
sudo systemctl start SERVICE. This starts the service immediately without enabling it to start at boot. For example,sudo systemctl start nginx. - Stop a service. Use
sudo systemctl stop SERVICE. This stops the service immediately. For example,sudo systemctl stop nginx. - Restart a service. Use
sudo systemctl restart SERVICE. This stops and then starts the service again, applying any configuration changes. For example,sudo systemctl restart nginx. - Reload a service (optional). If the service supports it,
sudo systemctl reload SERVICEreloads configuration files without a full restart. This is faster and avoids downtime. Not all services support reload; if not, you'll get an error. - Verify the change. After any command, run
systemctl status SERVICEagain to confirm the service is in the desired state. The status should showactive (running)for started, orinactive (dead)for stopped. - Enable or disable at boot (optional). To make a service start automatically at boot, use
sudo systemctl enable SERVICE. To stop it from starting at boot, usesudo systemctl disable SERVICE. These commands do not affect the current running state.
Common Mistakes
- Forgetting
sudo. Most service commands require root privileges. If you get a permission denied error, addsudobefore the command. - Using the wrong service name. Service names are case-sensitive and often include a
.servicesuffix. Check the exact name withsystemctl list-units. - Confusing
restartwithreload. Restart completely stops and starts the process; reload only re-reads configuration files. Use reload when possible to avoid downtime. - Assuming a service is enabled just because it's running. A service can be running but not enabled, meaning it won't start after a reboot. Use
systemctl is-enabled SERVICEto check.
Tips
- Use
systemctl status SERVICEafter any change to see a detailed view, including recent log entries. - To see all services that are currently running, use
systemctl list-units --type=service --state=running. - If you're editing configuration files, test the syntax before reloading. For example, for nginx, run
nginx -tbeforesystemctl reload nginx. - To see the dependencies of a service, use
systemctl list-dependencies SERVICE. - You can combine commands:
sudo systemctl restart SERVICE && systemctl status SERVICEruns status only if restart succeeds.
Troubleshooting
If a service does not start or stop as expected, follow these steps in order:
- Check the status and logs. Run
systemctl status SERVICE– it often shows the last few log lines. For more detailed logs, usejournalctl -u SERVICE(pressqto quit). Look for error messages like "Failed to start" or "Permission denied". - Verify the service file exists. Run
systemctl cat SERVICEto see the unit file. If it says "Unit file not found", the service name is wrong or the software isn't installed. - Check for syntax errors in configuration. If you recently edited a config file, run the service's own syntax check (e.g.,
nginx -t,apachectl configtest). Fix any errors and try again. - Look for port conflicts. If a service fails to bind to a port, check if another service is using it with
sudo ss -tulpnorsudo lsof -i :PORT. - Try a full restart of the system. If nothing else works,
sudo rebootcan clear temporary issues. This is a last resort but often resolves lingering problems. - If the service fails during start, check the system logs. Use
journalctl -xeto see the latest system errors. This can reveal missing dependencies or permission issues.
Frequently Asked Questions
How do I list all services?
Run systemctl list-units --type=service to see all loaded services. Add --all to include inactive ones.
What's the difference between start and enable?
start runs the service now, while enable makes it start automatically at boot. They are independent – you can start without enabling, or enable without starting.
Can I restart a service without sudo?
No, controlling services requires root privileges. You must use sudo or be logged in as root.
How do I make a service start on boot?
Use sudo systemctl enable SERVICE. To disable, use sudo systemctl disable SERVICE.
What does "Failed to restart" mean?
It means the service could not be restarted, often due to a configuration error, missing dependency, or the service crashing on start. Check the logs with journalctl -u SERVICE for details.
Is it safe to stop a service?
Generally yes, but stopping a critical service (like networking or SSH) can disrupt your system. Make sure you know what the service does before stopping it.