File suricata.init of Package suricata

#!/bin/bash
#
# chkconfig:    345 31 69
# description:  Suricata IDS
#
### BEGIN INIT INFO
# Provides:          suricata
# Required-Start:    $syslog $network $remote_fs
# Required-Stop:     $syslog $network $remote_fs
# Default-Start:     3 5
# Default-Stop:      0 1 2 4 6
# Short-Description: Suricata IDS
# Description:       Suricata is a high performance Network IDS, IPS and Network Security Monitoring
#	engine. Open Source and owned by a community run non-profit foundation,
#	the Open Information Security Foundation (OISF).
### END INIT INFO

SURICATA_BIN=/usr/bin/suricata
SURICATA_PID=/var/run/suricata.pid

if [ -r /etc/rc.status ]
then
  source /etc/rc.status
  START="/sbin/startproc"
  STATUS="/sbin/checkproc"
  SUCCESS="echo \$rc_done"
  FAILURE="echo \$rc_failed"
else
  source /etc/rc.d/init.d/functions
  START="daemon"
  STATUS="status"
  SUCCESS="success; echo"
  FAILURE="failure; echo"
fi

[ -r /etc/sysconfig/suricata ] && source /etc/sysconfig/suricata

ARGS="-D"

test -z "${CONFIG_FILE}"   || ARGS="${ARGS} -c ${CONFIG_FILE}"
test -z "${INTERFACE}"     || ARGS="${ARGS} -i ${INTERFACE}"
test -z "${QUEUE_ID}"      || ARGS="${ARGS} -q ${QUEUE_ID}"
test -z "${RULE_FILE}"     || ARGS="${ARGS} -s ${RULE_FILE}"
test -z "${LOG_DIRECTORY}" || ARGS="${ARGS} -l ${LOG_DIRECTORY}"
test -z "${USER}"          || ARGS="${ARGS} --user ${USER}"
test -z "${GROUP}"         || ARGS="${ARGS} --user ${GROUP}"

RETVAL=0

case "$1" in
  start)
    echo -n "Starting suricata: "
    ${START} ${SURICATA_BIN} ${ARGS}
    RETVAL=$?
    ;;
  stop)
    echo -n "Stopping suricata: "
    killproc ${SURICATA_BIN}
    RETVAL=$?
    ;;
  restart)
    if $0 checkconf
    then
      $0 stop
      $0 start
      unset RETVAL
    else
      exit 1
    fi
    ;;
  reload)
    if $0 checkconf
    then
      echo -n "Reloading configuration of suricata: "
      killproc ${SURICATA_BIN} -USR2
      RETVAL=$?
    else
      exit 1
    fi
    ;;
  status)
    echo -n "Status of suricata: "
    ${STATUS} ${SURICATA_BIN} > /dev/null 2>&1
    RETVAL=$?
    ;;
  checkconf)
    echo -n "Checking configuration of suricata: "
    ${SURICATA_BIN} -T > /dev/null 2>&1
    RETVAL=$?
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|reload|checkconf}"
    exit 1
    ;;
esac
[ -z ${RETVAL} ] && exit
[ ${RETVAL} -eq 0 ] && eval "${SUCCESS}" || eval "${FAILURE}"
exit ${RETVAL}