Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Start, Stop & Restart systemd Services (Linux)

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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 shows systemd, you're good.
  • Access to a terminal.
  • sudo privileges (administrative rights) to control services.
  • The exact name of the service you want to manage. You can find it with systemctl list-units --type=service or by checking the documentation of the software you installed.

Step-by-Step

  1. Identify the service name. Services are named like nginx.service, ssh.service, or docker.service. You can list all active services with systemctl list-units --type=service. If you're unsure, try systemctl status to see a list of running services.
  2. Check the current status. Before changing anything, see if the service is running, stopped, or failed. Run systemctl status SERVICE (replace SERVICE with the actual name). The output shows whether it's active (running) or inactive (dead).
  3. 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.
  4. Stop a service. Use sudo systemctl stop SERVICE. This stops the service immediately. For example, sudo systemctl stop nginx.
  5. 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.
  6. Reload a service (optional). If the service supports it, sudo systemctl reload SERVICE reloads configuration files without a full restart. This is faster and avoids downtime. Not all services support reload; if not, you'll get an error.
  7. Verify the change. After any command, run systemctl status SERVICE again to confirm the service is in the desired state. The status should show active (running) for started, or inactive (dead) for stopped.
  8. 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, use sudo 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, add sudo before the command.
  • Using the wrong service name. Service names are case-sensitive and often include a .service suffix. Check the exact name with systemctl list-units.
  • Confusing restart with reload. 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 SERVICE to check.

Tips

  • Use systemctl status SERVICE after 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 -t before systemctl reload nginx.
  • To see the dependencies of a service, use systemctl list-dependencies SERVICE.
  • You can combine commands: sudo systemctl restart SERVICE && systemctl status SERVICE runs status only if restart succeeds.

Troubleshooting

If a service does not start or stop as expected, follow these steps in order:

  1. Check the status and logs. Run systemctl status SERVICE – it often shows the last few log lines. For more detailed logs, use journalctl -u SERVICE (press q to quit). Look for error messages like "Failed to start" or "Permission denied".
  2. Verify the service file exists. Run systemctl cat SERVICE to see the unit file. If it says "Unit file not found", the service name is wrong or the software isn't installed.
  3. 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.
  4. Look for port conflicts. If a service fails to bind to a port, check if another service is using it with sudo ss -tulpn or sudo lsof -i :PORT.
  5. Try a full restart of the system. If nothing else works, sudo reboot can clear temporary issues. This is a last resort but often resolves lingering problems.
  6. If the service fails during start, check the system logs. Use journalctl -xe to 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.