• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL 7 : How to check the status of a service using systemd

by admin

Previous versions of CentOS/RedHat Linux use init scripts located in the /etc/rc.d/init directory to start and stop services. In CentOS/RHEL 7, these init scripts have been replaced with systemd service units. Service units have a .service extension. Use the systemctl command as follows to list all loaded service units:

# systemctl list-units --type service --all
  UNIT                                                            LOAD      ACTIVE   SUB     DESCRIPTION
  abrt-ccpp.service                                               loaded    inactive dead    Install ABRT coredump hook
  abrt-oops.service                                               loaded    inactive dead    ABRT kernel log watcher
  abrt-vmcore.service                                             loaded    inactive dead    Harvest vmcores for ABRT
  abrt-xorg.service                                               loaded    inactive dead    ABRT Xorg log watcher
  abrtd.service                                                   loaded    inactive dead    ABRT Automated Bug Reporting Tool

Check status of service with systemd

1. systemd service units correspond to system services. Use the following command to display detailed information about a service unit. This example displays information about the ntpd.service service unit. You can omit the .service extension if you want.

# systemctl status ntpd.service
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-08-26 15:01:55 IST; 2 months 20 days ago
 Main PID: 19984 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─19984 /usr/sbin/ntpd -u ntp:ntp -g

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

The following information is available for the specified service unit:

  • Loaded: If the service is loaded, the absolute path to the service unit file, and if the service unit is enabled
  • Active: If the service unit is running and a timestamp
  • Main PID: The Process ID of the corresponding system service and the service name
  • Status: Additional information about the corresponding system service
  • Process: Additional information about related processes
  • CGroup: Additional information about related Control Groups

The most recent log entries are displayed if the command is executed by the root user.

You would see the status of the service in green (if running) or in red (if stopped) as shown below.

service status check in RHEL CentOS 7

2. To list the status of all services:

# systemctl list-unit-files --type=service --all

For Example :

# systemctl list-unit-files --type=service
UNIT FILE                                     STATE
abrt-ccpp.service                             enabled
abrt-oops.service                             enabled
abrt-pstoreoops.service                       disabled
abrt-vmcore.service                           enabled
abrt-xorg.service                             enabled

You should see the service in disabled mode highlighted with red color and the service in enabled mode highlighted with green color as show below.

centOS RHEL 7 find service status

Other commands to check the status of service

Use the following command to check whether a service is running (active) or not running (inactive):

# systemctl is-active sshd
active

Use the following command to check whether a service is enabled or disabled:

# systemctl is-enabled sshd
enabled
# systemctl is-enabled httpd
disabled
CentOS / RHEL 7 : Beginners guide to systemd service units

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. How to Provide Credentials From a File While Mounting CIFS Share in Linux
  2. findmnt: command not found
  3. CentOS / RHEL 6 : How to configure kdump
  4. exec Command Examples in Linux
  5. perf: command not found
  6. How to Configure Existing Lvm Volume Group to Use DM-Multipath
  7. a2ensite Command Examples in Linux
  8. ark: command not found
  9. How to Install Mokutil package on CentOS/RHEL 7 and 8
  10. autopkgtest: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright