How to Check Background Service Status in Ubuntu?
Managing system services is a fundamental task for maintaining a
healthy Ubuntu environment. This article provides a quick guide on how
to check the status of a specific background service using the standard
systemctl command, explores variations for older systems,
and explains how to interpret the output.
The Standard Command: systemctl
In modern versions of Ubuntu (15.04 and later),
systemd is the default initialization system. The
primary tool used to manage and check the status of services is
systemctl.
To check the status of a specific background service, use the following syntax:
systemctl status service_name
For example, if you want to check the status of the Apache web server, you would run:
systemctl status apache2
This command does not require sudo privileges just to
view the status, though modifying the service (like stopping or
restarting it) will.
Understanding the Status Output
When you run the status command, Ubuntu provides a detailed breakdown of the service’s current state. The most critical pieces of information include:
- Loaded: Shows whether the service configuration file has been loaded into memory and the path to the service file.
- Active: Indicates if the service is running. You
will typically see
active (running)in green if everything is fine, orinactive (dead)if the service is stopped. - Main PID: The primary Process ID of the service, which is useful for deep troubleshooting.
- Tasks: The number of tasks and memory currently being consumed by the service.
- Recent Logs: The last few lines of the system log
(
journald) specific to that service, which quickly highlights recent errors.
Alternative Command for Older Ubuntu Versions
If you are maintaining an older legacy Ubuntu system that uses the
SysVinit or Upstart systems (Ubuntu
14.04 and earlier), the systemctl command will not work.
Instead, you must use the service command:
service service_name status
For example:
service mysql status
This command will output a shorter, more simplified status message indicating whether the process is currently running or stopped.