How To Check Service Status In Linux : Linux Service Status Check Command

Verifying a service’s status in Linux tells you whether it is active, inactive, or failed. Knowing how to check service status in linux is a fundamental skill for any system administrator or developer working with Linux servers. This guide walks you through every common method, from simple commands to advanced troubleshooting techniques.

You don’t need to be a Linux expert to check if a service is running. Most distributions use systemd, which makes status checks quick and consistent. Let’s start with the most direct approach.

Using Systemctl To Check Service Status

The systemctl command is the primary tool for managing services on modern Linux systems. It works on Ubuntu, Debian, CentOS, Fedora, and most other distributions using systemd.

To check a single service, open your terminal and type:

systemctl status <service-name>

For example, to check the SSH service:

systemctl status sshd

This command returns detailed information including the service state, main process ID, memory usage, and recent log entries. The output clearly shows whether the service is active (running), inactive (dead), or failed.

Interpreting Systemctl Status Output

The first line of output tells you the service name and description. The second line shows the loaded state and the unit file path. Look for the line starting with “Active:” – this is your key indicator.

  • Active (running) – The service is currently operational.
  • Active (exited) – The service ran and completed successfully, but isn’t running now.
  • Inactive (dead) – The service is not running and hasn’t been started.
  • Failed – The service attempted to start but encountered an error.

If you see “failed,” the output usually includes the exit code and a brief error message. This helps you diagnose what went wrong.

Checking Multiple Services At Once

You can check several services in one command by listing them with spaces:

systemctl status sshd nginx mysql

This shows the status of all three services in a single output block. It’s useful when troubleshooting a stack of applications.

How To Check Service Status In Linux Without Systemctl

Not every Linux system uses systemd. Older distributions or minimal containers might use SysV init or other init systems. Here’s how to check service status on those systems.

Using Service Command

The service command works on both SysV and systemd systems as a compatibility layer. The syntax is simple:

service <service-name> status

For example:

service apache2 status

This returns a short status message. On systemd systems, it internally calls systemctl. On SysV systems, it runs the init script directly.

Checking Init Scripts Directly

On older systems, you can run the init script located in /etc/init.d/:

/etc/init.d/<service-name> status

This method is rarely used today but remains valid for legacy environments. The output is usually a single line indicating running or stopped.

Checking Service Status With Systemd-Status

For a more concise view, use the systemd-status command. It’s less common but provides a cleaner output format:

systemd-status <service-name>

This command shows the same information as systemctl status but omits some verbose details. It’s handy when you want a quick glance without scrolling.

Using Pidof And Ps Commands

Sometimes you need to verify a service is running without using service management tools. The pidof command returns the process ID of a running program:

pidof sshd

If the service is running, you’ll see a number (the PID). If nothing appears, the service isn’t active. Similarly, ps can search for processes:

ps aux | grep sshd

This lists all processes matching “sshd.” Be aware that the grep command itself appears in the output – ignore that line.

Checking Listening Ports

Services often listen on network ports. You can verify a service is running by checking if its port is open:

ss -tuln | grep :22

Replace :22 with the port your service uses. If you see output, the service is listening. This method works even if the service manager reports differently.

Checking Service Status In Docker Containers

Inside a Docker container, you might not have systemd available. Use the docker exec command from the host to check services inside a container:

docker exec <container-name> systemctl status <service>

If systemd isn’t installed in the container, fall back to ps or service commands. Many minimal containers run only a single process, so checking the main process is often sufficient.

Automating Service Status Checks

You can write simple scripts to monitor services automatically. Here’s a basic bash example:

#!/bin/bash
SERVICE="nginx"
if systemctl is-active --quiet "$SERVICE"; then
    echo "$SERVICE is running"
else
    echo "$SERVICE is not running"
fi

This script uses systemctl is-active with the --quiet flag to suppress output. It returns an exit code of 0 if active, non-zero otherwise. You can integrate this into monitoring tools like Nagios or Zabbix.

Using Systemctl Is-Active

The is-active subcommand returns a simple status string:

systemctl is-active sshd

It prints “active” or “inactive.” This is perfect for scripts because the output is predictable and easy to parse.

Troubleshooting Failed Services

When a service fails to start, you need more than just its status. Use journalctl to view detailed logs:

journalctl -u <service-name> -n 50 --no-pager

This shows the last 50 log entries for the service. Look for error messages like “permission denied,” “port already in use,” or “configuration file not found.”

Common fixes include:

  • Checking configuration file syntax with nginx -t or apachectl configtest.
  • Ensuring required directories exist and have correct permissions.
  • Verifying that dependencies (like databases) are running first.

Restarting A Failed Service

After fixing the issue, restart the service:

systemctl restart <service-name>

Then check its status again. If it fails repeatedly, examine the logs more thoroughly. Sometimes the error message is misleading – search online for the exact error text.

Checking Service Status On Different Distributions

While systemd is standard, some distributions have quirks. On Ubuntu, services like Apache are named apache2, while on CentOS they’re httpd. Always verify the exact service name with:

systemctl list-units --type=service | grep -i <keyword>

This lists all services matching your keyword. On older Debian systems without systemd, use service --status-all to list all services and their states.

Using Top And Htop For Real-Time Status

For a dynamic view of running processes, use top or htop. These tools show all processes updating in real time. Press u in top to filter by user, or use / to search for a service name.

This method is less precise than systemctl but gives you context about resource usage. If a service is consuming 100% CPU, you’ll see it immediately.

Checking Service Status Remotely

You can check service status on remote servers using SSH:

ssh user@remote-server "systemctl status nginx"

This runs the command on the remote machine and returns the output to your local terminal. For multiple servers, consider using tools like Ansible or a simple loop in bash:

for server in server1 server2 server3; do
    ssh user@$server "systemctl is-active nginx"
done

This pattern is useful for checking the health of a cluster or load-balanced setup.

Common Mistakes When Checking Service Status

Beginners often confuse service names. For example, MySQL might be named mysql, mysqld, or mariadb depending on the distribution. Always confirm the exact name using systemctl list-units.

Another mistake is forgetting to use sudo. Some service status commands require root privileges. If you get “permission denied,” prepend sudo to your command.

Also, don’t rely solely on ps output. A process might appear running but be unresponsive due to a deadlock. Always check the service manager’s status for the most accurate state.

Using Graphical Tools

If you prefer a GUI, tools like Cockpit provide a web-based interface for managing services. Install it with:

sudo apt install cockpit   # Debian/Ubuntu
sudo yum install cockpit   # CentOS/RHEL

Then access https://your-server:9090 in a browser. The Services section shows all units with start/stop buttons and status indicators.

For desktop users, GNOME System Monitor or KSysGuard can show running processes, but they lack service-specific information like enabled/disabled state.

Checking Service Status In Containers And VMs

Inside a virtual machine, treat it like a normal Linux system. For containers, remember that many container images don’t include systemd. Use docker exec or kubectl exec to run commands inside the container.

In Kubernetes, check pod status with:

kubectl get pods

Then describe a specific pod to see container states:

kubectl describe pod <pod-name>

This shows whether containers are running, waiting, or crashed. It’s a different paradigm but serves the same purpose.

Best Practices For Service Monitoring

Don’t check service status manually every time. Set up automated monitoring with tools like Prometheus, Nagios, or simple cron jobs. A cron job running every minute can check critical services and send alerts if they fail.

Log all status checks for auditing. Redirect output to a file:

systemctl status nginx >> /var/log/service-checks.log

This creates a history you can review later. Also, use systemctl enable to ensure services start automatically after a reboot – otherwise they’ll remain inactive.

Frequently Asked Questions

What is the command to check service status in Linux?

The most common command is systemctl status <service-name>. For older systems, use service <service-name> status.

How do I check if a service is running in Linux without systemctl?

You can use ps aux | grep <service-name> or pidof <service-name>. Also check listening ports with ss -tuln.

How can I check service status for all services at once?

Use systemctl list-units --type=service --state=running to see only active services, or omit --state to see all.

Why does systemctl status show “inactive (dead)” for a running process?

This usually means the process was started manually, not through systemd. Use systemctl start to manage it properly, or check if the service name is correct.

How do I check service status in a Docker container?

Run docker exec <container-name> systemctl status <service> if systemd is available. Otherwise, use docker exec <container-name> ps aux to see running processes.

Mastering how to check service status in linux saves you time during troubleshooting and helps maintain system reliability. Start with systemctl status, explore the alternatives, and build scripts to automate your checks. With practice, you’ll diagnose service issues in seconds.