File init.d-graylog of Package graylog

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

# Author: Lee Briggs <lee@leebriggs.co.uk>

# Source function library.
. /etc/rc.d/init.d/functions

# Pull in sysconfig settings
[ -f /etc/sysconfig/graylog ] && . /etc/sysconfig/graylog

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Graylog Server"
NAME=graylog
CMD_LINE=$GRAYLOGCTL_DIR/graylogctl
LOCKFILE=/var/lock/subsys/$NAME
RUN=no

# Exit if the package is not installed
[ -e "$JAR_FILE" ] || exit 0
[ -x "$JAVA" ] || exit 0

start() {
    echo -n $"Starting ${NAME}: "
    (mkdir -p $(dirname ${GRAYLOG_PID});chown ${GRAYLOG_USER}. $(dirname ${GRAYLOG_PID}))
    daemon --user=${GRAYLOG_USER} $CMD_LINE start
    RETVAL=$?
    echo 
    sleep 2
    [ $RETVAL = 0 ] && touch ${LOCKFILE}
    return $RETVAL
}

stop() {
    echo -n $"Stopping ${NAME}: "
    $CMD_LINE stop
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${GRAYLOG_PID} && rm -f ${LOCKFILE}
    return $RETVAL
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status -p ${GRAYLOG_PID} $NAME
        RETVAL=$?
        ;;
    restart|force-reload)
        stop
        start
        ;;
    *)
        N=/etc/init.d/${NAME}
        echo "Usage: $N {start|stop|status|restart|force-reload}" >&2
        RETVAL=2
        ;;
esac

exit $RETVAL