#!/bin/sh
#SYSTEMS: Solaris, Linux
MSG="# Checking the Apache Web Server service..."
SYSTEM=`uname -s`
######Solaris######
if [ "$SYSTEM" = "SunOS" ]; then
  echo ""; echo "$MSG"
  case "`uname -r`" in
  5.[89]*) ;;
  *)
   #Only supported on Solaris 8 and newer
   exit 0;;
  esac
  CHK=`ls /etc/rc*.d/S*apache 2>/dev/null | tr "[\n]" " "`
  CONF=/etc/apache/httpd.conf
  PIDFILE=/var/run/httpd.pid
  PID=`ps -ef | grep httpd | grep -v grep`
  if [ "$CHK" != "" ]; then
    if [ ! -f ${CONF} ]; then       #No conf file so apache will not start...
      echo "--INFO-- [APACHE001i] The following Apache web server script(s) were found but do not appear to be configured to start: $CHK"
    else "--WARN-- [APACHE002f] The following Apache web server script(s) were found and appear to be configured to start: $CHK"
    fi
    if [ "$PID" != "" ]; then    #httpd daemon found running (a bad sign)...
      echo "--FAIL-- [APACHE003f] An httpd daemon is running!"
    fi 
  fi
fi
######Linux######
if [ "$SYSTEM" = "Linux" ]; then 
  echo ""; echo "$MSG"
  #Check if it shows up in the rc*.d directories.  Allow for multiple files found.
  CHK=`ls /etc/rc.d/rc*.d/S*httpd 2>/dev/null | tr "[\n]" " "`
    if [ "$CHK" != "" ]; then
      echo "--WARN-- [APACHE004w] Found 'httpd' service startup file(s): $CHK"
    fi
  #Check the process table
  PS=`ps -ef | grep "httpd" | grep -v "grep"`
  if [ "$PS" != "" ]; then 
    echo "--FAIL-- [APACHE005f] The Apache Web Service daemon (httpd) is currently running."
  fi
fi
