You are on page 1of 6

16/8/2016 CentOS/RHEL:CheckIfAServiceIsRunningOrNot

ME NU

nixCraft
LinuxandUnixtutorialsfornewandseasonedsysadmin.

CentOS/RHEL:CheckIfAServiceIsRunningOrNot
byV I V E K GI TE onJ UNE 9, 2013 las t updat ed DE CE MB E R 13, 2013
inCE NTOS ,MONI TORI NG,RE DHAT A ND FRI E NDS

H owdoIfindoutifaservicesuchasMySQLorApacherunningonmy
Centos/RHEL/FedoraLinuxserver?

Youneedtouseservicecommand.ItrunsaSystemVinitscriptinaspredictable
environmentaspossible,removingmostenvironmentvariablesandwithcurrentworking
directorysetto/.Thesyntaxisasfollows:

NetCrunchNetworkMonitoring

Allinonenetworkandsystemmonitoring
suitethatsetsupinminutes

Tosearch,typeandhitenter
30DaysFree

serviceSERVERstatus

OR

/etc/init.d/SERVERstatus

Examples

Find,outifaservicecalledmysqld(MySQLserver)isrunningonCentOSORRHEL.Open
aterminalorloginusingssh,enter:

#servicemysqldstatus

Sampleoutputs:

mysqld(pid7556)isrunning...

Findoutstatusofallservices
Theservicestatusallcommandrunsallinitscripts,inalphabeticalorder,withthe
statuscommand:

#servicestatusall

http://www.cyberciti.biz/faq/bashcheckifaserviceisrunningoncentosrhelserver/ 1/6
16/8/2016 CentOS/RHEL:CheckIfAServiceIsRunningOrNot

Sampleoutputs:

....
...
.....
irqbalance(pid2183)isrunning...
iscsiisstopped
iscsidisstopped
Kdumpisoperational
i5k_ambisa0000
Adapter:ISAadapter
Ch.0DIMM0:+63.0C(low=+127.5C,high=+127.5C)
Ch.0DIMM1:+56.5C(low=+127.5C,high=+127.5C)
Ch.1DIMM0:+62.0C(low=+127.5C,high=+127.5C)
Ch.1DIMM1:+49.0C(low=+127.5C,high=+127.5C)
Ch.2DIMM0:+54.0C(low=+127.5C,high=+127.5C)
Ch.3DIMM0:+49.0C(low=+127.5C,high=+127.5C)

coretempisa0000
Adapter:ISAadapter
Core0:+37.0C(high=+78.0C,crit=+100.0C)
Core1:+38.0C(high=+78.0C,crit=+100.0C)
Core2:+34.0C(high=+78.0C,crit=+100.0C)
Core3:+38.0C(high=+78.0C,crit=+100.0C)

coretempisa0001
Adapter:ISAadapter
Core0:+40.0C(high=+78.0C,crit=+100.0C)
Core1:+40.0C(high=+78.0C,crit=+100.0C)
Core2:+39.0C(high=+78.0C,crit=+100.0C)
Core3:+39.0C(high=+78.0C,crit=+100.0C)

w83627hfisa0290
Adapter:ISAadapter
in0:+4.08V(min=+0.00V,max=+4.08V)
in1:+4.08V(min=+0.00V,max=+4.08V)
in2:+4.08V(min=+2.82V,max=+3.79V)ALARM
in3:+3.07V(min=+4.08V,max=+4.05V)ALARM
in4:+3.12V(min=+4.08V,max=+4.08V)ALARM
in5:+3.15V(min=+4.08V,max=+4.06V)ALARM
in6:+3.20V(min=+4.08V,max=+4.06V)ALARM
Tosearch,typeandhitenter
in7:+3.28V(min=+3.82V,max=+4.06V)ALARM
in8:+3.28V(min=+4.06V,max=+4.06V)ALARM
fan1:0RPM(min=0RPM,div=2)
fan2:0RPM(min=0RPM,div=2)
fan3:0RPM(min=0RPM,div=2)
temp1:48.0C(high=+60.0C,hyst=+55.0C)sensor=thermistor
temp2:48.0C(high=+80.0C,hyst=+75.0C)sensor=thermistor
temp3:48.0C(high=+80.0C,hyst=+75.0C)sensor=thermistor
cpu0_vid:+1.419V
beep_enable:enabled

lvmetadisstopped
mdmonitorisstopped
memcached(pid45560)isrunning...
messagebus(pid7066)isrunning...
mysqld(pid7556)isrunning...
netconsolemodulenotloaded
Configureddevices:
loeth0eth1
Currentlyactivedevices:
loeth0eth1
rpc.svcgssdisstopped
rpc.mountd(pid7199)isrunning...
nfsd(pid72627261726072597258725772567255)isrunning...
rpc.rquotad(pid7195)isrunning...
rpc.statd(pid2215)isrunning...
ntpd(pid7295)isrunning...
master(pid7649)isrunning...
Processaccountingisenabled.
ipmi_msghandlermodulenotloaded.
ipmi_simodulenotloaded.
ipmi_devintfmodulenotloaded.
/dev/ipmi0doesnotexist.
quota_nldisstopped
rdiscisstopped
.....
..

psorpgrepcommand

Youcanusepsorpgrepcommandasfollowstofindoutifserviceisrunningornoton
RHEL/Centos:

http://www.cyberciti.biz/faq/bashcheckifaserviceisrunningoncentosrhelserver/ 2/6
16/8/2016 CentOS/RHEL:CheckIfAServiceIsRunningOrNot

#psaux|grep'serviceNameHere'
#psaux|grep'mysqld'

OR

#pgrepserviceNameHere
##matchusername##
#pgrepuuserNameserviceNameHere
#pgrepmysqld
#pgrepumysqlmysqld

Startingservice

Sayifaservicecalledhttpdisnotrunningonserverandyouwishtostartthesame:

#servicehttpdstatus
##ifhttpdisnotrunningstartit##
#chkconfighttpdon
#servicehttpdstart

References

Formoreinformationseemanpagesservice(8),pgrep(1),ps(1).

Sharethistutorialon:
Twitter Facebook Google+ DownloadPDFversion Foundanerror/typoonthispage?

Abouttheauthor:VivekGiteisaseasonedsysadminandatrainerfortheLinux/Unix&shell
scripting.FollowhimonTwitter.ORreadmorelikethis: Tosearch,typeandhitenter
LinuxReadCPUTemperatureSensorChipDataIncludingVoltageandFanSpeed
FATAL:Errorinsertingit87
Linux/UNIX:Findoutordetermineifprocesspidisrunning
FindoutifNFSServiceRunningOnLinux/UnixServer
LinuxVerifycrondDaemonAndCronjobsAreRunning
CantconnecttolocalMySQLserverthroughsocket
HowTo:FindoutIfMySQLIsRunningOnLinuxOrNot
RedHat/CentOS:Check/ListRunningServices
HowToSSHRestartMysqlServeronaLinuxandUnixCommandLine
UbuntuLinux:DisableApparmorForSpecificProfile/ServiceSuchAs

http://www.cyberciti.biz/faq/bashcheckifaserviceisrunningoncentosrhelserver/ 3/6
16/8/2016 CentOS/RHEL:CheckIfAServiceIsRunningOrNot

Commentsonthisentryareclosed.

Tosearch,typeandhitenter

JalalHajigholamali June10,2013,2:50am

Hi,
Thanksfornicearticle

someservicescreateafileunder/var/runwhenstarting
forexamplevsftpd.pidoratd.pid

wecancheckexistenceofthesefiles

LI NK

ZdenekStyblik June10,2013,7:09am

Hello,

Ithinkthereisatypo.AtfirstitssaidtouseserviceSERVERstatsor/etc/init.d/SERVER
stats.However,lateritsshowntousestatus,eg.#servicemysqldstatus.Ibelievethe
latteriscorrectandformerwrong.

Cheers!

LI NK

meow June10,2013,2:50pm

http://www.cyberciti.biz/faq/bashcheckifaserviceisrunningoncentosrhelserver/ 4/6
16/8/2016 CentOS/RHEL:CheckIfAServiceIsRunningOrNot

expectingRHEL7alongwithsystemd

LI NK

Angelos July10,2013,1:11pm

Ifonlyrealitywouldbealwayssorosy!

Therearecaseswhereaserviceiswedgedsobadlythatevenifyougiveitaservice
statuscommand,theoutputwellleadyouastray.SayforexampleopenVPN,ifitis
wedgedtheonlywaytofindoutistoPinganotherserver.
Othertimessomecustominitscripts,firsttramplethePIDfilebeforeissuingarealstart
command.Inthatcasesubsequentstatuscommandswillgiveyouerrors.

Sopleaseusetheoutputofthevariousservicestatuscommandsasadvicenotasthereal
status,therewillbecasesthatyouwillneedtodebugfurther.

GoodLuck

LI NK

sandy September21,2013,5:55pm

HIguysamnewtolinux,soHelpme
Howtogetdetails(forawebserver)thosewhocameandaccessthepagesandwhatare
Tosearch,typeandhitenter
alltheservicesrunningandfromwhichtimeit(services)startedtorun?

Thanksforresolvethis

LI NK

GauravBhayana December13,2013,10:33am

HiTeam

Pleaserectifythispost.BelowmentionedcommanddoesntexistinRHEL/CenrOS/
Fedora.

serviceSERVERstats
OR
/etc/init.d/SERVERstats

Itshouldbe

servicestatus
OR
/etc/init.d/status

LI NK

GauravBhayana December13,2013,10:35am
Itshouldbe

http://www.cyberciti.biz/faq/bashcheckifaserviceisrunningoncentosrhelserver/ 5/6
16/8/2016 CentOS/RHEL:CheckIfAServiceIsRunningOrNot

serviceservicenamestatus
OR
/etc/init.d/servicenamestatus

LI NK

Varun January8,2016,12:46am
Yeah..That`scorrect!!Thanks@Gaurav

#serviceservicenamestatus
OR
#/etc/init.d/servicenamestatus

LI NK

arefghobadi August16,2015,10:53am

Thanksfornicearticle

LI NK

NextFAQ:MacOSX:WakeUpServersUsingWakeonLAN(WOL)CommandUtility
PreviousFAQ:MacOSX:InstallGCCCompilerwithXcode
Tosearch,typeandhitenter

20002016nixCraft.Allrightsreserved.PrivacyTermsofServiceQuestionsorComments

http://www.cyberciti.biz/faq/bashcheckifaserviceisrunningoncentosrhelserver/ 6/6

You might also like