nagios-plugins icon indicating copy to clipboard operation
nagios-plugins copied to clipboard

check_service.sh Uses wrong command in CentOS 6.6

Open kitgerrits opened this issue 9 years ago • 2 comments

When I use this script on CentOS 6.6, it uses 'status' as command. Unfortunately, this does not see postfix as a valid job:

[root@hostname tmp] (@unknown.foo.com.) # status postfix status
status: Unknown job: postfix
[root@hostname tmp] (@unknown.foo.com.) # status --system postfix status
status: Unknown job: postfix

This is the 'RedHat' way to query status on CentOS 6:

[root@hostname tmp] (@unknown.foo.com.) # service postfix status
master (pid  1670) is running...

This is the 'RedHat' to query status on more recent versions:

[user@bar ~]$ systemctl status postfix.service
postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled)
   Active: active (running) since Sun 2015-03-22 13:20:46 CET; 2 months 9 days ago
 Main PID: 1200 (master)
   CGroup: name=systemd:/system/postfix.service
           ├─ 1200 /usr/libexec/postfix/master -w
           ├─ 1203 qmgr -l -t unix -u
           ├─ 1212 tlsmgr -l -t unix -u
           └─31388 pickup -l -t unix -u

Aug 31 17:12:50 hp-box.unknown.org postfix/smtp[31381]: connect to smtp.gmail.com[2a00:1450:4013:c01::6d]:587: Network...able

kitgerrits avatar Aug 31 '15 15:08 kitgerrits

This can be fixed by swapping the 'status' and the 'service' order.

Also, auto_os_detect in a nutshell:

auto_os_detect() {
  FOUND_OS=none
  if uname -a |grep -qi linux || grep -qi -s -e redhat -e centos -e mandriva -e mint -e debian /etc/*release /etc/debian_version /etc/issue
  then
    FOUND_OS=linux
  elif uname -a |grep -qi Darwin || ls /etc/asl |grep -qi apple
  then
    FOUND_OS=osx
  elif uname -a |grep -qi FreeBSD
  then
    FOUND_OS=freebsd
  elif oslevel |grep -qi aix
  then
    FOUND_OS=aix
  fi
  if [ "${FOUND_OS}" == "none" ]
  then
    echo Unable to detect your O/S
  else
    OS=${FOUND_OS}
  fi
}

I stuck this right above os_check:

if [ "${OS}" == "null" ]
then
  auto_os_detect
fi
os_check

kitgerrits avatar Aug 31 '15 17:08 kitgerrits

Reporting a similar issue under CentOS 6.8 :frowning:

Both initctl and service are present on the system, but service reports a greater number of services.

Changing the older of the conditions to have service at the top should be a safer bet, the service command acting as a generic wrapper around other service operations commands (in my understanding :beginner:).

p3r7 avatar Mar 22 '17 17:03 p3r7