# Kibana 4.2 as a service

**URL:** <https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426>\
**Category:** Kibana\
**Created:** [October 31, 2015, 4:45am UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426 "2015-10-31T04:45:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![niraj\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_kumar/32/4130_2.png) [@niraj\_kumar](https://discuss.elastic.co/u/niraj_kumar)\
**Post date:** [October 31, 2015, 4:45am UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426/1 "2015-10-31T04:45:40Z")

</div>

Hey All,

Kibana 4.2 is live and i really love it , but what really annoys me is that why can't be it run as a service like the usual elasticsearch and all which comes with a debian package. Is there a proper way to run it as a service?

Regards  
Niraj

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 31, 2015, 7:01am UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426/2 "2015-10-31T07:01:29Z")

</div>

Not yet, we're working on it though so keep your eyes out!

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 31, 2015, 11:21am UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426/3 "2015-10-31T11:21:11Z")

</div>

> Is there a proper way to run it as a service?

You speak as if it's not possible to run it as a daemon which obviously isn't true. It doesn't _ship_ with an init script but writing one shouldn't be hard and if you dig around the GitHub issues you'll find URLs to people who have done it. Also, if you dig out the GitHub issue concerning Debian packaging of Kibana, there's a URL to a complete 4.1.1 Debian package. I've been using it in production for a while and I'd expect the init script and what not to be usable with 4.2. too.

> Not yet, we're working on it though so keep your eyes out!

It baffles me why this wasn't part of the launch criteria, especially when the bulk of the work appears to have been completed anyway.

---

<div class="post-metadata">

**Author:** ![niraj\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_kumar/32/4130_2.png) [@niraj\_kumar](https://discuss.elastic.co/u/niraj_kumar)\
**Post date:** [October 31, 2015, 7:17pm UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426/4 "2015-10-31T19:17:58Z")

</div>

I believe i didn't mean that when i wrote it. Proper way here meant that is there a guidelines as how to do it. Anyways i wrote it myself and it worked Thanks for the help.

---

<div class="post-metadata">

**Author:** ![niraj\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_kumar/32/4130_2.png) [@niraj\_kumar](https://discuss.elastic.co/u/niraj_kumar)\
**Post date:** [October 31, 2015, 7:18pm UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426/5 "2015-10-31T19:18:45Z")

</div>

Thanks @warkolm , that helps 😄

---

<div class="post-metadata">

**Author:** ![voipoclay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/voipoclay/32/4372_2.png) [@voipoclay](https://discuss.elastic.co/u/voipoclay)\
**Post date:** [November 2, 2015, 3:28am UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426/6 "2015-11-02T03:28:02Z")

</div>

I just made myself a script under /etc/init/kibana.conf on ubuntu 14.04

```
 description "Kibana 4 Service"
    
 stop on runlevel [!12345]
    
 respawn
    
 # location of kibana
 exec /usr/local/src/kibana-4.2.0-linux-x64/bin/kibana      

```

> initctl start kibana

---

<div class="post-metadata">

**Author:** ![StephenGoodall](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@StephenGoodall](https://discuss.elastic.co/u/StephenGoodall)\
**Post date:** [November 2, 2015, 5:29pm UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426/7 "2015-11-02T17:29:56Z")

</div>

I've just spent the day upgrading to ES 2.0 and kibana 4.2.0 (really wanted the black theme 😃 )

I found that the init script I previously used for Kibana 4.1.1 did not work for 4.2.0, after lots of changes I think I narrowed it down to the user it runs as, the old script ran the service as "nobody", when I changed this to ubuntu it started up and worked.

When I had the user as "nobody" the "sudo service kibana start" command returned "OK" but didn't actually start up.

Thought I'd mention this in case it helps anyone else out 🙂 I also changed a couple of log\_progress\_msg lines to log\_daemon\_msg as they didn't seem to print either.

This was on Ubuntu 14.04 on EC2 if it helps anyone.

---

<div class="post-metadata">

**Author:** ![RustyWilson](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@RustyWilson](https://discuss.elastic.co/u/RustyWilson)\
**Post date:** [November 7, 2015, 11:14pm UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426/8 "2015-11-07T23:14:57Z")

</div>

Here's an Init script that I've developed. It runs kibana as a service, and logs it's actions to /var/log/kibana.log in json format so it matches kibana's default output.

This has been tested on Ubuntu 14.04.3 LTS, but it should work on any system that uses modern init.d scripts.

type sudo -i to get root then just copy and paste the entire contents into the terminal.

I've also created a github repository:

[https://github.com/rlwmmw/kibana-4.2-init](https://github.com/rlwmmw/kibana-4.2-init)

then type service kibana (start|stop|restart|status|reload). Cheers!

```
SCRIPT_DIR="/etc/init.d"
SCRIPT_NAME="kibana"
update-rc.d -f "$SCRIPT_NAME" remove && rm "$SCRIPT_DIR/$SCRIPT_NAME"
vim "$SCRIPT_DIR/$SCRIPT_NAME" && chmod +x "$SCRIPT_DIR/$SCRIPT_NAME" && update-rc.d "$SCRIPT_NAME" defaults
:imap kj <Esc>
i#!/bin/bash
#set -x
### BEGIN INIT INFO
#
# Provides: kibana
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Kibana 4.2 init script
# Description: Starts Kibana 4.2 as a daemon.
#
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
export PATH

## Check to see if we are running as root first.
if [`id -u` -ne 0]; then
   echo "You need root privileges to run this script"
   exit 1
fi

## Kibana 4.2 Init Script.
PROG_NAME="kibana"
PID_PATH="/var/run"
PID_FILE="$PID_PATH/$PROG_NAME"
PROG_PATH="/bin/kibana/bin"
PROG_LOGDIR=/var/log/$PROG_NAME

if ! [-e "$PROG_LOGDIR"]; then
    mkdir -p $PROG_LOGDIR
fi

start() {
    if [-e "$PID_PATH/$PROG_NAME.pid"]; then
        ## Kibana is already running, exit with error.
        echo "Error! $PROG_NAME is currently running!" 1>&2
        exit 1
    else
		DATE="$(date '+%FT%T:%:z')"
		echo '{"type":"log","@timestamp":"'$DATE'","tags":["start","info"],"pid":$PROG_PID,"message":"Kibana has been started with /etc/init.d/kibana '$PROG_ARGS'"}' >>"$PROG_LOGDIR/$PROG_NAME.log"
		exec "$PROG_PATH/$PROG_NAME" >>"$PROG_LOGDIR/$PROG_NAME.log" 2>&1 &
        PROG_PID="$!"
		printf "$PROG_PID\n" >"$PID_PATH/$PROG_NAME.pid"
		echo "$PROG_NAME started with PID: $PROG_PID"
    fi
}

stop() {
	if [-e "$PID_PATH/$PROG_NAME.pid"]; then
        ## Program is running, so stop it
		PROG_PID="$(cat $PID_PATH/$PROG_NAME.pid)"
        kill -TERM $PROG_PID
		if [$? == "0"]; then
            rm "$PID_PATH/$PROG_NAME.pid"
		    DATE="$(date '+%FT%T:%:z')"
		    echo '{"type":"log","@timestamp":"'$DATE'","tags":["stopped","info"],"pid":$PROG_PID,"message":"Kibana has been stopped with /etc/init.d/kibana '$PROG_ARGS'"}' >>"$PROG_LOGDIR/$PROG_NAME.log"
			echo "$PROG_NAME has stopped"
		else
			echo "Error!: $PROG_NAME has failed to stop! Check PID: $PROG_PID."
			exit 1
		fi
    else
        ## Program is not running, exit with error.
        echo "Error!: $PROG_NAME does not appear to be running!" 1>&2
    fi
}
status() {
    if [-e "$PID_PATH/$PROG_NAME.pid"]; then
	    PROG_PID="$(cat $PID_PATH/$PROG_NAME.pid)"
		ps -l | grep " $PROG_PID " | grep -v grep
		if [$? == "0"]; then
            echo "$PROG_NAME is running with PID: $PROG_PID"
		else
		    ps -aux | grep "$PROG_NAME" | grep -v grep
			if [$? == "0"]; then
				PROG_PID="$(ps -aux | grep "$PROG_NAME" | grep -v grep | awk '{ print $2 }')"
			    printf "$PROG_PID\n" >"$PID_PATH/$PROG_NAME.pid"
			    echo "$PROG_NAME is running with PID: $PROG_PID"
			else
			    rm "$PID_PATH/$PROG_NAME.pid"
				echo "$PROG_NAME is not running"
			fi
		fi
    else 
        ## Program is not running
        echo "$PROG_NAME is not running"
    fi
}
case "$1" in
    start)
		PROG_ARGS="start"
        start
        exit 0
    ;;
    stop)
        PROG_ARGS="stop"
		stop
        exit 0
    ;;
    status)
		PROG_ARGS="status"
        status
        exit 0
    ;;
    reload)
		PROG_ARGS="reload"
        stop
        start
        exit 0
    ;;
	restart)
	    PROG_ARGS="restart"
        stop
        start
        exit 0
	;;
    **)
        echo "Usage: $0 {start|stop|restart|status|reload}" 1>&2
        exit 1
    ;;
esac
kj
:wq

```

---

<div class="post-metadata">

**Author:** ![talk2cshah](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@talk2cshah](https://discuss.elastic.co/u/talk2cshah)\
**Post date:** [June 17, 2016, 7:31am UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426/9 "2016-06-17T07:31:46Z")

</div>

> [@niraj\_kumar](#):
>
> elieve i didn't mean that when i wrote it. Proper way here meant that is there a guidelines as how to do it. Anyways i wrote it myself and it worked Thanks for the help.

Hi Niraj,

For a quick help.. what did you do to make Kibana run as a service...

Regards,

---

<div class="post-metadata">

**Author:** ![niraj\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_kumar/32/4130_2.png) [@niraj\_kumar](https://discuss.elastic.co/u/niraj_kumar)\
**Post date:** [June 17, 2016, 3:45pm UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426/10 "2016-06-17T15:45:21Z")

</div>

description "Kibana 4 as a service"

start on runlevel [2345]  
stop on runlevel [!2345]

exec su root -c "exec /home/niraj/Downloads/kibana-4.2.0-linux-x64/bin/kibana" \>\> /var/log/kibana.log 2\>&1

create a file in /etc/init and paste the above config

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:50pm UTC](https://discuss.elastic.co/t/kibana-4-2-as-a-service/33426/11 "2017-07-06T13:50:04Z")

</div>


