How To Check If A Service Is Running Linux : Check Service Running Status

Ensuring system reliability starts with knowing how to check if a service is running Linux using systemctl status. This guide will show you multiple ways to monitor services, from basic commands to advanced troubleshooting, so you can keep your server healthy and responsive.

Whether you manage a home server or a production environment, services can fail without warning. Knowing how to check if a service is running Linux quickly saves you time and prevents downtime. Let’s dive into the most effective methods.

Understanding Linux Services And Systemd

Linux services are background processes that start automatically or on demand. They handle tasks like web servers, databases, and SSH connections. Modern Linux distributions use systemd as the init system to manage these services.

Systemd replaces older SysV init scripts and provides consistent commands. Most major distros like Ubuntu, Debian, CentOS, and Fedora now rely on systemd. If you’re using an older system, you might need alternative commands.

What Is A Service In Linux

A service is a program that runs in the background without direct user interaction. Examples include Apache (web server), MySQL (database), and cron (scheduled tasks). Services are defined by unit files that tell systemd how to start, stop, and monitor them.

Unit files are stored in /etc/systemd/system/ or /lib/systemd/system/. Each service has a .service extension. Understanding this structure helps you locate and inspect services manually.

How To Check If A Service Is Running Linux

The most straightforward way to check a service is with the systemctl command. This tool is part of systemd and gives you detailed status information. Here’s how to use it.

Using Systemctl Status Command

Open your terminal and type:

systemctl status <service-name>

Replace <service-name> with the actual service name, like nginx or sshd. The output shows whether the service is active, inactive, or failed. It also displays recent log entries.

Example output for a running service:

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2025-01-20 10:15:30 UTC; 2h 15min ago
   Main PID: 1234 (nginx)
   Tasks: 2 (limit: 1114)
   Memory: 5.2M
   CGroup: /system.slice/nginx.service
           ├─1234 nginx: master process /usr/sbin/nginx
           └─1235 nginx: worker process

Look for the line starting with Active:. If it says active (running), the service is up. If it says inactive (dead) or failed, the service is not running.

Checking Multiple Services At Once

You can list all services and their statuses with:

systemctl list-units --type=service --state=running

This shows only active services. To see all services, including stopped ones, use:

systemctl list-units --type=service --all

These commands help you quickly scan your system for issues. Combine them with grep to filter specific services.

Using The Is-Active Flag

For scripting or quick checks, use the is-active subcommand:

systemctl is-active <service-name>

This returns a simple word: active, inactive, or unknown. It’s perfect for automated monitoring scripts.

Example:

systemctl is-active sshd

If the service is running, you see active. If not, you see inactive. This is faster than parsing full status output.

Alternative Methods For Non-Systemd Systems

Some older Linux distributions still use SysV init or Upstart. If you’re on such a system, the commands differ slightly. Here are the alternatives.

Using Service Command

The service command works on many older systems:

service <service-name> status

This returns a status message like nginx is running or nginx is not running. It’s simple but less detailed than systemctl.

Example:

service apache2 status

Checking Init Scripts Directly

On SysV systems, services have scripts in /etc/init.d/. You can run them directly:

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

This works identically to the service command. It’s useful if the service wrapper is missing.

Checking Service Status With Process Commands

Sometimes systemd isn’t available, or you want to verify manually. Process commands like ps and pgrep let you check if a service’s process is alive.

Using Ps Command

The ps command lists all running processes. To check for a specific service:

ps aux | grep <service-name>

For example, to check Apache:

ps aux | grep apache

If the service is running, you see one or more lines with the process details. If not, you only see the grep command itself. Be careful: the grep line always appears, so look for actual process entries.

To exclude the grep line, use:

ps aux | grep [a]pache

The bracket trick prevents grep from matching itself.

Using Pgrep And Pidof

These commands are cleaner for scripts:

pgrep <service-name>

Returns the process ID if the service is running, or nothing if it’s not. Similarly:

pidof <service-name>

Both are quick and avoid parsing output. Use them in conditional statements for automation.

Checking Network Services With Port Commands

Many services listen on network ports. Checking port availability confirms the service is accepting connections. This is especially useful for web servers, databases, and SSH.

Using Netstat

The netstat command shows network connections and listening ports:

netstat -tuln | grep <port-number>

For example, to check if SSH (port 22) is listening:

netstat -tuln | grep :22

If you see a line with LISTEN, the service is running. The flags mean:

  • -t – TCP ports
  • -u – UDP ports
  • -l – listening sockets
  • -n – numeric addresses (no DNS lookup)

Using Ss Command

The ss command is modern and faster than netstat. Use it similarly:

ss -tuln | grep <port-number>

Example:

ss -tuln | grep :80

This checks if a web server is listening on port 80. The output is similar to netstat but more efficient.

Checking Service Status With Journalctl

Systemd logs all service activity to the journal. You can use journalctl to see recent logs and confirm the service is running without errors.

Viewing Logs For A Specific Service

Use:

journalctl -u <service-name> -n 20

This shows the last 20 log entries for the service. Look for messages like Started <service-name> or Listening on port. Errors appear as FAILED or ERROR.

To follow logs in real time:

journalctl -u <service-name> -f

This is useful when debugging startup issues.

Automating Service Checks With Scripts

You can combine these commands into simple scripts to monitor services automatically. Here’s a basic example.

Bash Script To Check Service

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

This script checks if nginx is active. If not, it tries to restart it. The --quiet flag suppresses output, making it suitable for cron jobs.

Save this script and run it periodically with cron or a systemd timer.

Using Cron For Regular Checks

Add the script to your crontab:

*/5 * * * * /path/to/check-service.sh

This runs the check every five minutes. Adjust the interval based on your needs.

Common Service Status Messages And What They Mean

When you run systemctl status, you see several status lines. Here’s what each means.

Active (Running)

The service is currently executing and functioning normally.

Active (Exited)

The service ran and completed successfully, but it’s not a daemon. This is normal for one-time tasks.

Active (Waiting)

The service is running but waiting for an event. Rare but possible.

Inactive (Dead)

The service is stopped and not running. It may have been manually stopped or never started.

Failed

The service attempted to start but encountered an error. Check logs for details.

Enabling Vs Starting

A service can be enabled (starts on boot) but not currently active. Use systemctl enable to enable and systemctl start to start immediately.

Troubleshooting When A Service Won’t Start

If a service fails to start, follow these steps to diagnose the issue.

Check Logs With Journalctl

Run journalctl -u <service-name> -xe for extended log details. The -x flag adds explanations, and -e jumps to the end.

Verify Configuration Files

Many services have syntax check commands. For example:

nginx -t

This tests the nginx configuration for errors. Fix any reported issues.

Check Dependencies

Some services depend on others. Use systemctl list-dependencies <service-name> to see what’s required. Ensure all dependencies are running.

Inspect Permissions

Service files and directories must have correct permissions. Check ownership with ls -l and adjust with chown if needed.

Using Graphical Tools For Service Management

If you prefer a GUI, several tools exist. They’re less common on servers but useful for desktop Linux.

Cockpit Web Console

Cockpit provides a web-based interface for managing services. Install it with:

sudo apt install cockpit

Then access https://your-server:9090. The Services section shows status, logs, and controls.

Systemd-Gtk

This lightweight GUI shows systemd units. Install via your package manager. It’s simple but functional.

Best Practices For Service Monitoring

Regularly checking services is good, but automation is better. Here are some tips.

Set Up Monitoring Tools

Use tools like Nagios, Zabbix, or Prometheus to monitor services automatically. They alert you when a service fails.

Enable Log Rotation

Logs can fill your disk. Configure logrotate to manage log files and prevent space issues.

Document Your Services

Keep a list of critical services and their expected status. This helps during troubleshooting.

Test Restarts

Periodically test restarting services to ensure they come back cleanly. This builds confidence in your recovery procedures.

Frequently Asked Questions

How Do I Check If A Service Is Running In Linux Without Systemctl?

Use ps aux | grep <service-name> or service <service-name> status for older systems. The pgrep command also works.

What Is The Difference Between Systemctl Status And Systemctl Is-active?

systemctl status shows detailed information including logs. systemctl is-active returns only a single word: active, inactive, or unknown. Use is-active for scripts.

Can I Check A Service Status Remotely?

Yes, use SSH to run commands on the remote machine. For example: ssh user@server systemctl status nginx. Some tools like Cockpit also offer remote access.

Why Does Systemctl Show A Service As Active But It’s Not Responding?

The service process may be stuck or misconfigured. Check logs with journalctl -u <service-name> and test network connectivity with curl or telnet.

How Do I List All Running Services In Linux?

Use systemctl list-units --type=service --state=running. For older systems, try service --status-all.

Conclusion

Knowing how to check if a service is running Linux is a fundamental skill for any system administrator. You’ve learned multiple methods: systemctl for modern systems, service for legacy ones, process commands like ps and pgrep, and network tools like ss and netstat. Each approach has its place, and combining them gives you a complete picture of your system’s health.

Start by mastering systemctl status—it’s the most comprehensive tool. Then build scripts to automate checks and alerts. With practice, you’ll quickly identify and resolve service issues, keeping your Linux environment stable and reliable.

Remember to check logs regularly and document your services. A proactive approach saves hours of troubleshooting later. Now go ahead and test these commands on your system—you’ll be a service-checking expert in no time.