Created
July 17, 2015 11:57
-
-
Save marclop/6f4fa4aeef76d18dd7ef to your computer and use it in GitHub Desktop.
kibana4init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# /etc/init.d/kibana4 -- startup script for kibana4 | |
# | |
### BEGIN INIT INFO | |
# Provides: kibana4 | |
# Required-Start: $network $remote_fs $named | |
# Required-Stop: $network $remote_fs $named | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Starts kibana4 | |
# Description: Starts kibana4 using start-stop-daemon | |
### END INIT INFO | |
#configure this with wherever you unpacked kibana: | |
NAME=kibana | |
KIBANA_BIN=/opt/kibana/bin | |
PID_FILE=/var/run/$NAME.pid | |
PATH=/bin:/usr/bin:/sbin:/usr/sbin:$KIBANA_BIN | |
DAEMON=$KIBANA_BIN/kibana | |
DAEMON_ARGS="" | |
DESC="Kibana4" | |
LOG=/var/log/kibana4.log | |
pid_file_exists() { | |
[ -f "$PID_FILE" ] | |
} | |
do_start() { | |
if pid_file_exists | |
then | |
echo "Kibana is already running" | |
else | |
$DAEMON $DAEMON_ARGS 1>"$LOG" 2>&1 & | |
echo $! > "$PID_FILE" | |
PID=$! | |
if [ "$PID" > 0 ] | |
then | |
echo "Kibana started with pid $!" | |
else | |
echo "Kibana could not be started" | |
fi | |
fi | |
} | |
do_status() { | |
if pid_file_exists | |
then | |
PID=$(cat $PID_FILE) | |
STATUS=$(ps ax | grep $PID | grep -v grep | awk '{print $1}') | |
if [ "$STATUS" == "$PID" ] | |
then | |
echo "Kibana is running on proccess $PID" | |
else | |
echo "Kibana is NOT running" | |
rm $PID_FILE | |
fi | |
else | |
echo "Kibana is NOT running" | |
fi | |
} | |
do_stop() { | |
if pid_file_exists | |
then | |
PID=$(cat $PID_FILE) | |
STATUS=$(ps ax | grep $PID | grep -v grep | awk '{print $1}') | |
if [ "$STATUS" == "$PID" ] | |
then | |
echo "Killing Kibana...." | |
KILL=$(kill -15 $PID) | |
rm $PID_FILE | |
sleep 1 | |
echo -e "\tKibana (PID:$PID) killed" | |
else | |
echo "Kibana is NOT running" | |
rm $PID_FILE | |
fi | |
else | |
echo "Kibana is NOT running" | |
fi | |
} | |
case "$1" in | |
start) | |
do_start;; | |
stop) | |
do_stop | |
;; | |
status) | |
do_status | |
;; | |
restart) | |
do_stop | |
do_start | |
;; | |
*) | |
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2 | |
exit 3 | |
;; | |
esac | |
: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment