#!/bin/sh
### BEGIN INIT INFO
# Provides:          graylog
# Required-Start:    $syslog $remote_fs
# Should-Start:      $time ypbind smtp
# Required-Stop:     $syslog $remote_fs
# Should-Stop:       ypbind smtp
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Graylog Web
# Description:       Graylog Web - Search your logs, create charts, send reports and be alerted when something happens.
### END INIT INFO

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
SERVICE_NAME="Graylog Web Interface"

# Check for existence of needed config file and read it
GRAYLOG_CONFIG=/etc/sysconfig/graylog-web-interface
test -r $GRAYLOG_CONFIG || { echo "$GRAYLOG_CONFIG not existing";
	if [ "$1" = "stop" ]; then exit 0;
	else exit 6; fi; }
. $GRAYLOG_CONFIG

CMD_LINE=${WEB_HOME}/bin/graylog-web-interface
PID_FILE=/var/run/graylog/graylog-web-interface.pid
. /etc/rc.status
# Reset status of this service
rc_reset

case "$1" in
    start)
	echo -n "Starting  ${SERVICE_NAME}"
	/sbin/startproc -u $WEB_USER -s $CMD_LINE -Dconfig.file=${WEB_CONF} -Dlogger.file=${WEB_LOG_CONF} -Dpidfile.path=${PID_FILE} -Dhttps.keyStore=${WEB_KEYSTORE} ${WEB_CMD_PARAMS}
	rc_status -v
	;;
    stop)
	echo -n "Shutting down ${SERVICE_NAME} "
	/sbin/killproc -TERM -p $PID_FILE
	rc_status -v
	;;
    restart)
	$0 stop
	$0 start
	rc_status
	;;
    reload)
	echo -n "Reload service ${SERVICE_NAME} "
	$0 restart
	rc_status -v
	;;
    status)
	echo -n "Checking for service ${SERVICE_NAME} "
	/sbin/checkproc -p $PID_FILE $CMD_LINE
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|reload}"
	exit 1
	;;
esac
rc_exit
