====== CentOS/RHEL7 Check service ======
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
===== Check status of service with systemd =====
- 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.
{{ :linux:service-status-check-in-rhel-centos-7.png |}}
- 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.
{{ :linux:centos-rhel-7-find-service-status.png |}}
===== 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