Devaraj C
Devaraj C

Reputation: 337

Kibana 4 start as service in ubuntu 12.04

Im trying to start kibana 4 as a service in ubuntu 12.04. Please any one help on how to set as service .

I referred these links to write the script , but it wont work.

https://github.com/akabdog/scripts/blob/master/kibana4_init

https://github.com/chovy/node-startup/blob/master/init.d/node-app

Upvotes: 1

Views: 4989

Answers (3)

Devaraj C
Devaraj C

Reputation: 337

Below code is worked for me.

#!/bin/sh
KIBANA_EXEC="/opt/kibana/bin/kibana"
LOG_FILE="/var/log/kibana/.log"
PID_FILE="/var/run/kibana.pid"
PID_DIR="$APP_DIR/pid"
LOG_DIR="$APP_DIR/log"

USAGE="Usage: $0 {start|stop|restart|status} [--force]"
FORCE_OP=false

start_it() {
    mkdir -p "$PID_DIR"
    mkdir -p "$LOG_DIR"
    sleep 10
    echo "Starting Kibana..."
    $KIBANA_EXEC 1>"$LOG_FILE" 2>&1 &
    echo $! > "$PID_FILE"
    echo "Kibana started with pid $!"
}

pid_file_exists() {
[ -f "$PID_FILE" ]
}
get_pid() {
echo "$(cat "$PID_FILE")"
}
is_running() {
PID=$(get_pid)
! [ -z "$(ps aux | awk '{print $2}' | grep "^$PID$")" ]
}

remove_pid_file() {
echo "Removing pid file"
rm -f "$PID_FILE"
}

start_app() {
if pid_file_exists
then
if is_running
then
PID=$(get_pid)
echo "Kibana already running with pid $PID"
exit 1
else
echo "Kibana stopped, but pid file exists"
if [ $FORCE_OP = true ]
then
echo "Forcing start anyways"
remove_pid_file
start_it
fi
fi
else
start_it
fi
}


stop_process() {
PID=$(get_pid)
echo "Killing process $PID"
kill $PID
}

stop_app() {
if pid_file_exists
then
if is_running
then
echo "Stopping kibana ..."
stop_process
remove_pid_file
echo "Kibana stopped"
else
echo "Kibana already stopped, but pid file exists"
if [ $FORCE_OP = true ]
then
echo "Forcing stop anyways ..."
remove_pid_file
echo "Kibana stopped"
else
exit 1
fi
fi
else
echo "Kibana already stopped, pid file does not exist"
exit 1
fi
}


status_app() {
if pid_file_exists
then
if is_running
then
PID=$(get_pid)
echo "Kibana running with pid $PID"
else
echo "Kibana stopped, but pid file exists"
fi
else
echo "Kibana stopped"
fi
}


case "$2" in
--force)
FORCE_OP=true
;;
"")
;;
*)
echo $USAGE
exit 1
;;
esac
case "$1" in
start)
start_app
;;
stop)
stop_app
;;
restart)
stop_app
start_app
;;
status)
status_app
;;
*)
echo $USAGE
exit 1
;;
esac

Upvotes: 3

prem
prem

Reputation: 604

Small error with the script.In the LogFile path you need to specify at the end .log

Upvotes: 1

user4667700
user4667700

Reputation: 1

There seems to be a small error in the init script. The PID_FILE varible uses the $NAME varible but NAME isn't defined until later. Move the NAME variable before the PID_FILE variable.

Upvotes: 0

Related Questions