≡ Menu

CentOS / RHEL: Check If A Service Is Running Or Not

How do I find out if a service such as MySQL or Apache running on my Centos/RHEL/Fedora Linux server?

You need to use service command. It runs a System V init script in as predictable environment as possible, removing most environment variables and with current working directory set to /. The syntax is as follows:
Tutorial details
DifficultyEasy (rss)
Root privilegesYes
Requirementsservice command
Estimated completion timeLess than a minute

service SERVER status

OR

/etc/init.d/SERVER status

Examples

Find, out if a service called mysqld (MySQL server) is running on CentOS OR RHEL. Open a terminal or login using ssh, enter:
# service mysqld status

Sample outputs:

mysqld (pid  7556) is running...

Find out status of all services

The service --status-all command runs all init scripts, in alphabetical order, with the status command:
# service --status-all
Sample outputs:

....
...
.....
irqbalance (pid 2183) is running...
iscsi is stopped
iscsid is stopped
Kdump is operational
i5k_amb-isa-0000
Adapter: ISA adapter
Ch. 0 DIMM 0: +63.0°C  (low  = +127.5°C, high = +127.5°C)  
Ch. 0 DIMM 1: +56.5°C  (low  = +127.5°C, high = +127.5°C)  
Ch. 1 DIMM 0: +62.0°C  (low  = +127.5°C, high = +127.5°C)  
Ch. 1 DIMM 1: +49.0°C  (low  = +127.5°C, high = +127.5°C)  
Ch. 2 DIMM 0: +54.0°C  (low  = +127.5°C, high = +127.5°C)  
Ch. 3 DIMM 0: +49.0°C  (low  = +127.5°C, high = +127.5°C)  
 
coretemp-isa-0000
Adapter: ISA adapter
Core 0:      +37.0°C  (high = +78.0°C, crit = +100.0°C)  
Core 1:      +38.0°C  (high = +78.0°C, crit = +100.0°C)  
Core 2:      +34.0°C  (high = +78.0°C, crit = +100.0°C)  
Core 3:      +38.0°C  (high = +78.0°C, crit = +100.0°C)  
 
coretemp-isa-0001
Adapter: ISA adapter
Core 0:      +40.0°C  (high = +78.0°C, crit = +100.0°C)  
Core 1:      +40.0°C  (high = +78.0°C, crit = +100.0°C)  
Core 2:      +39.0°C  (high = +78.0°C, crit = +100.0°C)  
Core 3:      +39.0°C  (high = +78.0°C, crit = +100.0°C)  
 
w83627hf-isa-0290
Adapter: ISA adapter
in0:         +4.08 V  (min =  +0.00 V, max =  +4.08 V)   
in1:         +4.08 V  (min =  +0.00 V, max =  +4.08 V)   
in2:         +4.08 V  (min =  +2.82 V, max =  +3.79 V)   ALARM
in3:         +3.07 V  (min =  +4.08 V, max =  +4.05 V)   ALARM
in4:         +3.12 V  (min =  +4.08 V, max =  +4.08 V)   ALARM
in5:         +3.15 V  (min =  +4.08 V, max =  +4.06 V)   ALARM
in6:         +3.20 V  (min =  +4.08 V, max =  +4.06 V)   ALARM
in7:         +3.28 V  (min =  +3.82 V, max =  +4.06 V)   ALARM
in8:         +3.28 V  (min =  +4.06 V, max =  +4.06 V)   ALARM
fan1:          0 RPM  (min =    0 RPM, div = 2)
fan2:          0 RPM  (min =    0 RPM, div = 2)
fan3:          0 RPM  (min =    0 RPM, div = 2)
temp1:       -48.0°C  (high = +60.0°C, hyst = +55.0°C)  sensor = thermistor
temp2:       -48.0°C  (high = +80.0°C, hyst = +75.0°C)  sensor = thermistor
temp3:       -48.0°C  (high = +80.0°C, hyst = +75.0°C)  sensor = thermistor
cpu0_vid:   +1.419 V
beep_enable:enabled
 
lvmetad is stopped
mdmonitor is stopped
memcached (pid  45560) is running...
messagebus (pid  7066) is running...
mysqld (pid  7556) is running...
netconsole module not loaded
Configured devices:
lo eth0 eth1
Currently active devices:
lo eth0 eth1
rpc.svcgssd is stopped
rpc.mountd (pid 7199) is running...
nfsd (pid 7262 7261 7260 7259 7258 7257 7256 7255) is running...
rpc.rquotad (pid 7195) is running...
rpc.statd (pid  2215) is running...
ntpd (pid  7295) is running...
master (pid  7649) is running...
Process accounting is enabled.
ipmi_msghandler module not loaded.
ipmi_si module not loaded.
ipmi_devintf module not loaded.
/dev/ipmi0 does not exist.
quota_nld is stopped
rdisc is stopped
.....
..
 

ps or pgrep command

You can use ps or pgrep command as follows to find out if service is running or not on RHEL/Centos:
# ps aux | grep 'serviceNameHere'
# ps aux | grep 'mysqld'

OR
# pgrep serviceNameHere
## match user name ##
# pgrep -u userName serviceNameHere
# pgrep mysqld
# pgrep -u mysql mysqld

Starting service

Say if a service called httpd is not running on server and you wish to start the same:
# service httpd status
## if httpd is not running start it ##
# chkconfig httpd on
# service httpd start

References

For more information see man pages - service(8), pgrep(1), ps(1).

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 8 comments… add one }

  • Jalal Hajigholamali June 10, 2013, 2:50 am

    Hi,
    Thanks for nice article

    some services create a file under /var/run when starting
    for example vsftpd.pid or atd.pid

    we can check existence of these files

  • Zdenek Styblik June 10, 2013, 7:09 am

    Hello,

    I think there is a typo. At first it’s said to use “service SERVER stats” or “/etc/init.d/SERVER stats”. However, later it’s shown to use ‘status’, eg. “# service mysqld status”. I believe the latter is correct and former wrong.

    Cheers!

  • meow June 10, 2013, 2:50 pm

    expecting RHEL 7 along with systemd

  • Angelos July 10, 2013, 1:11 pm

    If only reality would be always so rosy !

    There are cases where a service is wedged so badly that even if you give it a service status command , the output well lead you astray. Say for example openVPN , if it is wedged the only way to find out is to Ping another server.
    Other times some custom init scripts, first trample the PID file before issuing a real start command. In that case subsequent status commands will give you errors.

    So please use the output of the various service status commands as advice not as the real status, there will be cases that you will need to debug further.

    Good Luck

  • sandy September 21, 2013, 5:55 pm

    HI guys am new to linux, so Help me
    How to get details (for a web server) those who came and access the pages and what are all the services running and from which time it(services) started to run?

    Thanks for resolve this

  • Gaurav Bhayana December 13, 2013, 10:33 am

    Hi Team

    Please rectify this post. Below mentioned command doesn’t exist in RHEL / CenrOS / Fedora.

    service SERVER stats
    OR
    /etc/init.d/SERVER stats

    It should be

    service status
    OR
    /etc/init.d/ status

    • Gaurav Bhayana December 13, 2013, 10:35 am

      It should be

      service service-name status
      OR
      /etc/init.d/service-name status

  • aref ghobadi August 16, 2015, 10:53 am

    Thanks for nice article

Leave a Comment