# Kibana 4 as Service

**URL:** <https://discuss.elastic.co/t/kibana-4-as-service/22419>\
**Category:** Elasticsearch\
**Created:** [February 26, 2015, 8:29pm UTC](https://discuss.elastic.co/t/kibana-4-as-service/22419 "2015-02-26T20:29:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Teodoro\_Hochfarber\_S](https://avatars.discourse-cdn.com/v4/letter/t/5f8ce5/32.png) [@Teodoro\_Hochfarber\_S](https://discuss.elastic.co/u/Teodoro_Hochfarber_S)\
**Post date:** [February 26, 2015, 8:29pm UTC](https://discuss.elastic.co/t/kibana-4-as-service/22419/1 "2015-02-26T20:29:16Z")

</div>

Hi.  
I've created a init.d file to run Kibana 4 as a service. As I couldn't find  
anywhere a init that worked in RedHat 6.6 I created this one, that should  
work in most Linux distros.  
It has been tested in RH6.6, Ubuntu 14.10 and Centos 7. Enjoy!

#!/bin/bash  
PATH=/sbin:/usr/sbin:/bin:/usr/bin  
DESC="Kibana 4"  
NAME=kibana  
DAEMON=/var/www/html/Kibana/bin/$NAME  
DAEMON\_ARGS=""  
PIDFILE=/var/run/$NAME.pid  
SCRIPTNAME=/etc/init.d/$NAME  
LOG=/var/www/html/Kibana/bin/kibana.log

pid\_file\_exists() {  
[-f "$PIDFILE"]  
}

do\_start() {

```
    if pid_file_exists
    then
                    echo "Kibana is already running"
    else
                    $DAEMON $DAEMON_ARGS 1>"$LOG" 2>&1 &
                    echo $! > "$PIDFILE"
                    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 $PIDFILE)  
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 $PIDFILE
            fi
    else
            echo "Kibana is NOT running"
    fi

```

}

do\_stop() {  
if pid\_file\_exists  
then  
PID=$(cat $PIDFILE)  
STATUS=$(ps ax | grep $PID | grep -v grep | awk '{print $1}')

```
            if ["$STATUS" == "$PID"]
            then
                            echo "Killing Kibana...."
                            KILL=$(kill -15 $PID)
                            rm $PIDFILE
                            sleep 1
                            echo -e "\tKibana (PID:$PID) killed"
                            
            else
                            echo "Kibana is NOT running"
                            rm $PIDFILE
            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

:

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3b901b4c-c9d9-4035-a13b-f685a3fca60e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3b901b4c-c9d9-4035-a13b-f685a3fca60e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Omer\_Uludag](https://avatars.discourse-cdn.com/v4/letter/o/b9e5f3/32.png) [@Omer\_Uludag](https://discuss.elastic.co/u/Omer_Uludag)\
**Post date:** [December 2, 2015, 8:54pm UTC](https://discuss.elastic.co/t/kibana-4-as-service/22419/2 "2015-12-02T20:54:17Z")

</div>

> [@Teodoro\_Hochfarber\_S](#):
>
> #!/bin/bash  
> PATH=/sbin:/usr/sbin:/bin:/usr/bin  
> DESC="Kibana 4"  
> NAME=kibana  
> DAEMON=/var/www/html/Kibana/bin/$NAME  
> DAEMON\_ARGS=""  
> PIDFILE=/var/run/$NAME.pid  
> SCRIPTNAME=/etc/init.d/$NAME  
> LOG=/var/www/html/Kibana/bin/kibana.log
> 
> pid\_file\_exists() {  
> [-f "$PIDFILE"]  
> }
> 
> do\_start() {
> 
> ```
> if pid_file_exists
> then
> echo "Kibana is already running"
> else
> $DAEMON $DAEMON_ARGS 1&gt;"$LOG" 2&gt;&1 &
> echo $! &gt; "$PIDFILE"
> PID=$!
> if ["$PID" &gt; 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 $PIDFILE)  
> 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 $PIDFILE
> fi
> else
> echo "Kibana is NOT running"
> fi
> 
> ```
> 
> }
> 
> do\_stop() {  
> if pid\_file\_exists  
> then  
> PID=$(cat $PIDFILE)  
> STATUS=$(ps ax | grep $PID | grep -v grep | awk '{print $1}')
> 
> ```
> if ["$STATUS" == "$PID"]
> then
> echo "Killing Kibana...."
> KILL=$(kill -15 $PID)
> rm $PIDFILE
> sleep 1
> echo -e "\tKibana (PID:$PID) killed"
>                             
> else
> echo "Kibana is NOT running"
> rm $PIDFILE
> 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
> 
> :

Hi can you maybe specify where I have to put this code? 🙂

---

<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 5, 2017, 11:34pm UTC](https://discuss.elastic.co/t/kibana-4-as-service/22419/3 "2017-07-05T23:34:04Z")

</div>


