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 | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | service command |
Time | Less 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 – ps(1).
🐧 9 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
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
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!
expecting RHEL 7 along with systemd
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
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
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
It should be
service service-name status
OR
/etc/init.d/service-name status
Yeah.. That`s correct !! Thanks @Gaurav
# service service-name status
OR
# /etc/init.d/service-name status
Thanks for nice article