view Kibana.rc @ 26:610835fb4209

external configuration for kibana
author Carl Byington <carl@five-ten-sg.com>
date Fri, 03 May 2013 08:04:08 -0700
parents d058481276aa
children 76544ad0561d
line wrap: on
line source

#!/bin/bash
#
#	/etc/rc.d/init.d/Kibana
#
#	Starts Kibana as a daemon
#
# chkconfig: 2345 20 80
# description: Starts Kibana as a daemon
# pidfile: /var/run/Kibana.pid

### BEGIN INIT INFO
# Provides: Kibana
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: Kibana
# Description: Starts Kibana as a daemon.

### END INIT INFO

. /etc/sysconfig/Kibana

DESC="Kibana Daemon"
JAVA=$(which java 2>/dev/null)
if [ "$(which jruby 2>/dev/null)" == '' ]; then
    JRUBY_CMD="$JAVA $JAVAARGS -jar /usr/share/jruby.jar"
else
    JRUBY_CMD="jruby"
fi
LOGFILE=/var/log/Kibana/Kibana.log
PIDFILE=/var/run/Kibana.pid
base=Kibana

. /etc/init.d/functions

#
# Function that starts the daemon/service
#
do_start() {
    cd /usr/share/java/Kibana
    pid=$(
    exec sudo -u kibana /bin/bash - <<EOF
        export GEM_HOME=$(pwd)
        export GEM_PATH=
        export JAVA_MEM=$JAVA_MEM
        export JAVA_STACK=$JAVA_STACK
        export KIBANA_HOST=$KIBANA_HOST
        export KIBANA_PORT=$KIBANA_PORT
        export KIBANA_ES=$KIBANA_ES
        $JRUBY_CMD kibana.rb >>$LOGFILE 2>&1 &
        echo \$!
EOF
    )
    echo $pid >$PIDFILE
    [ -n "$pid" ] && success $"$base startup" || failure $"$base startup"
}


#
# Function that stops the daemon/service
#
do_stop() {
    killproc -p $PIDFILE Kibana
}


case "$1" in
  start)
    echo -n "Starting $DESC: "
    do_start
    touch /var/lock/subsys/$base
    ;;
  stop)
    echo -n "Stopping $DESC: "
    do_stop
    rm /var/lock/subsys/$base 2>/dev/null
    rm $PIDFILE               2>/dev/null
    ;;
  restart)
    echo -n "Restarting $DESC: "
    do_stop
    do_start
    ;;
  reload)
    echo -n "Reloading $DESC: "
    pid=$(cat $PIDFILE)
    [ -n "$pid" ] && pkill -HUP -u Kibana -P $pid
    ;;
  status)
    echo -n "$base "
    status -p $PIDFILE
    ;;
  *)
    echo "Usage: service $base {start|stop|status|restart}" >&2
    exit 3
    ;;
esac

echo
exit 0