How to Stop a Service in Ubuntu

The Resource Reclamation Vector

When administering a Linux server, you may occasionally need to halt a background service (a daemon) without actually uninstalling the software. For example, if you are migrating a database, you must temporarily stop the MySQL service to prevent it from writing new data while you copy the files. Simply killing the process ID is dangerous and can lead to data corruption; you must gracefully instruct the system manager to spin the service down.

How to Stop a Service

Modern Ubuntu installations rely on `systemd` to manage all background services. You must utilize the `systemctl` utility to safely execute the shutdown sequence.

1. Open your terminal application or connect to the server via SSH.
2. Because stopping a system service alters the operational state of the server, you must execute the command with superuser privileges.
3. The syntax requires the `systemctl` command, the `stop` directive, and the exact name of the target service. For example, to stop the Apache web server, type:

sudo systemctl stop apache2.service

4. Press Enter.
5. The system will prompt you for your administrative password. Type it blindly (no characters will appear) and press Enter.
6. The Execution Reality: If the command is successful, the terminal will return a blank prompt. The service is now completely halted and consuming zero CPU cycles.
7. Verification (Crucial Step): Never assume the command worked perfectly. Always interrogate the kernel to verify the service is dead. Execute the status command:

sudo systemctl status apache2.service

The terminal will output a block of text. You must verify that the third line explicitly states `Active: inactive (dead)`. To restart the service when your maintenance is complete, simply replace the word `stop` with `start` in the original command.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.