#!/bin/sh

# Copyright (C) 2015, Wazuh Inc.
# OSSEC         Controls Wazuh on Redhat-based systems
# Author:       Kayvan A. Sylvan <kayvan@sylvan.com>
# Author:       Daniel B. Cid <dcid@ossec.net>
#
# chkconfig: 2345 99 15
# description: Starts and stops Wazuh (Host Intrusion Detection System)
#
# This will work on Redhat systems (maybe others too)

# Source function library.
export LANG=C

. /etc/init.d/functions

WAZUH_HOME=/var/ossec
WAZUH_CONTROL="$WAZUH_HOME/bin/wazuh-control"

start() {
    echo -n "Starting Wazuh: "
    ${WAZUH_CONTROL} start > /dev/null
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        success
    else
        failure
    fi
    echo
    return $RETVAL
}

stop() {
    echo -n "Stopping Wazuh: "
    ${WAZUH_CONTROL} stop > /dev/null
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        success
    else
        failure
    fi
    echo
    return $RETVAL
}

status() {
    ${WAZUH_CONTROL} status
    RETVAL=$?
    return $RETVAL
}

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

exit $?
