0
0
Linux-cliHow-ToBeginner · 3 min read

How to Stop a Service in Linux: Simple Commands Explained

To stop a service in Linux, use the systemctl stop service-name command on systems with systemd. On older systems, use service service-name stop. Replace service-name with the actual service you want to stop.
📐

Syntax

There are two common commands to stop services in Linux depending on your system's init system:

  • systemctl stop service-name: Stops the service using systemd, the modern init system.
  • service service-name stop: Stops the service on older systems using SysVinit or Upstart.

Replace service-name with the exact name of the service you want to stop.

bash
systemctl stop service-name

service service-name stop
💻

Example

This example shows how to stop the apache2 web server service using systemctl. It demonstrates the command and the expected output when successful.

bash
sudo systemctl stop apache2
sudo systemctl status apache2
Output
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: inactive (dead) since Fri 2024-06-07 10:00:00 UTC; 2s ago Main PID: 1234 (code=exited, status=0/SUCCESS) Jun 07 10:00:00 hostname systemd[1]: Stopped The Apache HTTP Server.
⚠️

Common Pitfalls

Common mistakes when stopping services include:

  • Using the wrong command for your system's init system (e.g., using service on a systemd system).
  • Not running the command with sudo or as root, which is required to stop services.
  • Misspelling the service name, causing the command to fail silently or show an error.
  • Expecting the service to stop immediately without checking its status.
bash
sudo service apache2 stop  # Older systems
sudo systemctl stop apache2  # Modern systems

# Wrong: missing sudo
systemctl stop apache2

# Wrong: misspelled service name
sudo systemctl stop apche2
📊

Quick Reference

CommandDescription
systemctl stop service-nameStop a service on systemd-based systems
service service-name stopStop a service on SysVinit or Upstart systems
sudo systemctl status service-nameCheck the status of a service
sudo systemctl start service-nameStart a service
sudo systemctl restart service-nameRestart a service

Key Takeaways

Use systemctl stop service-name on modern Linux systems with systemd.
Use service service-name stop on older Linux systems without systemd.
Always run stop commands with sudo or as root to have permission.
Double-check the service name to avoid errors.
Verify the service status after stopping to confirm it stopped successfully.