#!/bin/sh
# OSSEC         Controls OSSEC HIDS on Redhat-based systems
# Author:       Kayvan A. Sylvan <kayvan@sylvan.com>
# Author:       Daniel B. Cid <dcid@ossec.net>
# Author:       Michael Starks <ossec@michaelstarks.com>
#
# chkconfig: 2345 99 15
# description: Starts and stops OSSEC HIDS (Host Intrusion Detection
System)
#
# This will work on Redhat systems (maybe others too)

# Source function library.
export LANG=C

. /etc/init.d/functions
[ -e /etc/ossec-init.conf ] && . /etc/ossec-init.conf

if [ "X${DIRECTORY}" = "X" ]; then
    DIRECTORY="/var/ossec"
fi

INITS="/etc/ossec-init.conf /etc/ossec/ossec-init-*.conf"

start() {
        for i in $INITS; do
        [ -e $i ] && . $i
        if [ -d ${DIRECTORY} ]; then
          echo -n "Starting OSSEC at ${DIRECTORY}: "
          ${DIRECTORY}/bin/ossec-control start > /dev/null
          RETVAL=$?
          if [ $RETVAL -eq 0 ]; then
                success
          else
                failure
          fi
          echo
        else
          /bin/rm -f $i
        fi
        done
        return $RETVAL
}

stop() {
        for i in $INITS; do
        [ -e $i ] && . $i
        if [ -d ${DIRECTORY} ]; then
          echo -n "Stopping OSSEC at ${DIRECTORY}: "
          ${DIRECTORY}/bin/ossec-control stop > /dev/null
          RETVAL=$?
            if [ $RETVAL -eq 0 ]; then
                success
            else
                failure
            fi
          echo
        fi
        done
        return $RETVAL
}

status() {
        for i in $INITS; do
        [ -e $i ] && . $i
        if [ -d ${DIRECTORY} ]; then
        echo Status for ${DIRECTORY}:
        ${DIRECTORY}/bin/ossec-control status
        fi
        done
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  status)
    status
        ;;
  *)
        echo "*** Usage: ossec {start|stop|restart|status}"
        exit 1
esac

exit $?


