Skip to main content

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


We can use service command to get the status of services running on the system. It runs a System V init script in as predictable environment as possible, removing most environment variables and with current working directory set to /.


Syntax is:


service <service-name> status


OR


/etc/init.d/<service-name> status


Example:


Find, out if a service called httpd (Apache Web Server) is running on CentOS OR RHEL. Open a terminal or login using ssh, enter:


  #  service httpd status


Sample outputs:


[root@myserver ~]# service httpd status


httpd (pid  21585) 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 output:-


[root@myserver ~]# service --status-all

anacron is stopped

atd is stopped

auditd is stopped

cpuspeed is stopped

crond (pid 3442) is running...

cupsd (pid 5004) is running...

gpm (pid 3316) is running...

hald is stopped

httpd is stopped

ipmi_msghandler module not loaded.

ipmi_si module not loaded.

ipmi_devintf module not loaded.

/dev/ipmi0 does not exist.

Firewall is stopped.

irqbalance (pid 3031) is running...

Usage: jboss {start|stop|restart}

Usage: jboss {start|stop|restart}

mdmpd is stopped

dbus-daemon-1 is stopped

/etc/init.d/microcode_ctl: reading microcode status is not yet supported

Server address not specified in /etc/sysconfig/netdump

netplugd is stopped

Configured devices:

lo eth0

Currently active devices:

lo eth0

NetworkManager is stopped

nscd is stopped

ntpd (pid 3117) is running...

rhnsd (pid 3498) is running...

saslauthd is stopped

sendmail (pid 3145 3135) is running...

smartd is stopped

snmpd (pid 5035) is running...

snmptrapd is stopped

sshd (pid 32692 32690 31125 31123 31007 31005 28859 28828 27800 27797 25769 25763 24868 24865 24453 24451 23420 23417 22077 22072 21991 21989 21578 21576 21185 21183 20987 20984 20757 20755 20665 20661 19843 19837 18508 18490 18447 18445 15355 15349 15268 15266 11588 11580 11106 11104 8560 8557 8494 8428 8426 8425 8408 7597 7591 7450 7448 6677 6671 5249 5233 4776 4772 4570 4563 3084 2807 2805 2307 2305 1909 1907 1548 1545) is running...

syslogd (pid 3014) is running...

klogd (pid 3018) is running...

vsftpd is stopped

winbindd is stopped

wpa_supplicant is stopped

xfs (pid 3463) is running...

xinetd (pid 4898) is running...


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 'serviceName'
 # ps aux | grep 'httpd'


Comments

Popular posts from this blog

CentOS / Redhat : Configure CentOS as a Software Router with two interfaces

Linux can be easily configured to share an internet connection using iptables. All you need to have is, two network interface cards as follows: a) Your internal (LAN) network connected via eth0 with static ip address 192.168.0.1 b) Your external WAN) network is connected via eth1 with static ip address 10.10.10.1  ( public IP provided by ISP ) Please note that interface eth1 may have public IP address or IP assigned by ISP. eth1 may be connected to a dedicated DSL / ADSL / WAN / Cable router: Step # 1: Enable Packet Forwarding Login as the root user. Open /etc/sysctl.conf file # vi /etc/sysctl.conf Add the following line to enable packet forwarding for IPv4: net.ipv4.conf.default.forwarding=1 Save and close the file. Restart networking: # service network restart Step # 2: Enable IP masquerading In Linux networking, Network Address Translation (NAT) or Network Masquerading (IP Masquerading) is a technique of transceivin

Linux Find Command: Find Files Modified On Specific Date

There are many situations in which we have to find out  all files that have been modified on a specific date  using find command under Linux. There are two ways to list files in given directory modified after given date of the current year. The latest version of GNU/find command use the following syntax: Syntax GNU/find latest version: find /path/to/dir -newermt "date" find /path/to/dir -newermt "May 13" find /path/to/dir -newermt "yyyy-mm-dd" ## List all files modified on given date find /path/to/dir -newermt yyyy-mm-dd ! -newermt yyyy-mm-dd -ls ### print all *.sh ### find /path/to/dir -newermt "yyyy-mm-dd" -print -type f -iname "*.sh" The other way of doing this works on the versions of find before v4.3.3: touch -t 02010000 /tmp/timestamp find /usr -newer /tmp/timestamp then we can remove the reference file: rm -f /tmp/stamp$$ To  find out all Shell Script files  (*.sh) in /home/linux/scripts that have been modifie

Shell Script: Find Number Of Arguments Passed

Many times , when we create shell scripts we try to do repetitive tasks through functions. Some functions take arguments & we have to check the no. of arguments that are passed to it. Each bash shell function has the following set of shell variables: [a] All function parameters or arguments can be accessed via  $1, $2, $3,..., $N . [b]  $*  or  $@  holds all parameters or arguments passed to the function. [c]  $#  holds the number of positional parameters passed to the function. [d] An array variable called  FUNCNAME  ontains the names of all shell functions currently in the execution call stack. Example Create a shell script as follows: #!/bin/bash # Purpose: Demo bash function # -----------------------------   ## Define a function called test() test(){   echo "Function name:  ${FUNCNAME}"   echo "The number of positional parameter : $#"   echo "All parameters or arguments passed to the function: '$@'"   e