A Beginner's Guide to Starting and Stopping Linux Services
This beginner-friendly guide explains how to start, stop, restart, and manage Linux services using the systemctl command. It covers practical examples for controlling services immediately and across reboots, with a quick reference table for the most common Linux service commands.
If you've ever installed a web server, database, or SSH daemon on a Linux machine, you quickly realize that installing software is only half the job. You also need to know how to start, stop, and control Linux services once they're running. This is a core skill for any Linux administrator, and it's tested directly on the CompTIA Linux+ exam.
In this post, we'll walk through the essentials of managing services in Linux using systemd, the init system used by most modern Linux distributions including Ubuntu, CentOS, RHEL, and Fedora.
What Is a Linux Service?
A service (sometimes called a daemon) is a background process that runs on your system, often starting at boot time. Common examples include:
- sshd: the OpenSSH daemon for remote access
- nginx or apache2: web servers
- cron: the task scheduler
- NetworkManager: handles network connections
In modern Linux systems, these services are managed by systemd, which uses a command-line tool called systemctl to interact with them.
The Core Tool: systemctl
The systemctl command is your primary interface for managing services in Linux. Think of it as the control panel for your system's background processes. Most systemctl commands follow this basic pattern:
sudo systemctl [action] [service-name]Let's walk through the most important actions you'll use day to day.
Starting a Service
To start a service that isn't currently running, use the start action. For example, to start the Apache web server:
sudo systemctl start apache2This starts the service immediately, but it does not configure it to start automatically on reboot.
Stopping a Service
To stop a running service, use the stop action:
sudo systemctl stop apache2The service will shut down gracefully. If you need it to start again after a reboot, this won't affect that behavior either.
Restarting and Reloading
After making configuration changes, you'll often need to restart a service to apply them. You have two options:
- restart: stops and starts the service completely, causing a brief interruption
- reload: asks the service to re-read its config file without fully stopping, if supported
sudo systemctl restart apache2
sudo systemctl reload apache2Use reload when uptime matters and the service supports it. Use restart when a full reset is needed.
Checking Service Status
One of the most useful Linux service commands is status. It shows whether the service is running, when it started, and the most recent log entries:
sudo systemctl status apache2You'll see output similar to this:
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled)
Active: active (running) since Mon 2024-01-15 09:32:10 UTC; 2h ago
Main PID: 1234 (apache2)
Tasks: 55
Memory: 12.5MThe Active: active (running) line tells you the service is healthy. If you see failed or inactive, that's a signal to investigate further.
Enabling and Disabling Services at Boot
Starting a service with systemctl start only affects the current session. To control Linux services across reboots, you need to enable or disable them:
sudo systemctl enable apache2
sudo systemctl disable apache2Enabling a service creates a symlink that tells systemd to start it automatically at boot. Disabling removes that symlink. You can combine both actions in one step:
sudo systemctl enable --now apache2The --now flag starts the service immediately and enables it for future reboots at the same time. This is a handy shortcut worth remembering.
Quick Reference Table
- start: starts the service right now
- stop: stops the service right now
- restart: stops and starts the service
- reload: reloads config without full restart
- status: shows current state and recent logs
- enable: configures service to start at boot
- disable: prevents service from starting at boot
- enable --now: enables and starts immediately
What's Next
Now that you can start, stop, and control Linux services confidently, the next logical step is understanding how to view and manage the logs those services generate. In the next post, we'll explore journalctl, the systemd journal tool that lets you filter and troubleshoot service logs like a pro.
Tools and resources for this topic
- CompTIA Linux+ Study Guide — Comprehensive Linux+ exam preparation covering system administration, security, and scripting.