126 lines
3.6 KiB
Bash
126 lines
3.6 KiB
Bash
#!/bin/sh
|
|
# Init script for kibana
|
|
# Created by Thomas Neuburger
|
|
# Implemented based on SLE11_3 /etc/init.d/skeleton file
|
|
#
|
|
### BEGIN INIT INFO
|
|
# Provides: kibana
|
|
# Required-Start: $syslog $remote_fs
|
|
# Should-Start: $time ypbind smtp
|
|
# Required-Stop: $syslog $remote_fs
|
|
# Should-Stop: ypbind smtp
|
|
# Default-Start: 3 5
|
|
# Default-Stop: 0 1 2 6
|
|
# Short-Description: Starts Kibana as Daemon
|
|
# Description: Starts Kibana as Daemon (based on node.js)
|
|
### END INIT INFO
|
|
|
|
# set defaults
|
|
CONFIG_PATH=/etc/kibana/
|
|
LOG_PATH=/var/log/kibana
|
|
USER=kibana
|
|
GROUP=kibana
|
|
|
|
# Check for missing binaries (stale symlinks should not happen)
|
|
# Note: Special treatment of stop for LSB conformance
|
|
KIBANA_BIN=/opt/kibana/bin/kibana
|
|
test -x $KIBANA_BIN || { echo "$KIBANA_BIN not installed";
|
|
if [ "$1" = "stop" ]; then exit 0;
|
|
else exit 5; fi; }
|
|
|
|
# Check for existence of needed config file and read it
|
|
KIBANA_CONFIG=/etc/sysconfig/kibana
|
|
test -r $KIBANA_CONFIG || { echo "$KIBANA_CONFIG not existing";
|
|
if [ "$1" = "stop" ]; then exit 0;
|
|
else exit 6; fi; }
|
|
|
|
# Read config
|
|
. $KIBANA_CONFIG
|
|
|
|
name=kibana
|
|
pidfile="/var/run/$name.pid"
|
|
|
|
# Export config path (later usage by /opt/kibana/src/cli/serve/serve.js)
|
|
export CONFIG_PATH
|
|
|
|
# Create PID file with correct rights
|
|
touch $pidfile
|
|
chown ${USER}: $pidfile
|
|
|
|
# Shell functions sourced from /etc/rc.status:
|
|
# rc_check check and set local and overall rc status
|
|
# rc_status check and set local and overall rc status
|
|
# rc_status -v be verbose in local rc status and clear it afterwards
|
|
# rc_status -v -r ditto and clear both the local and overall rc status
|
|
# rc_status -s display "skipped" and exit with status 3
|
|
# rc_status -u display "unused" and exit with status 3
|
|
# rc_failed set local and overall rc status to failed
|
|
# rc_failed <num> set local and overall rc status to <num>
|
|
# rc_reset clear both the local and overall rc status
|
|
# rc_exit exit appropriate to overall rc status
|
|
# rc_active checks whether a service is activated by symlinks
|
|
. /etc/rc.status
|
|
|
|
# Reset status of this service
|
|
rc_reset
|
|
|
|
case "$1" in
|
|
start)
|
|
echo -n "Starting $name "
|
|
if [ -s $pidfile -a -d /proc/$(<$pidfile) ]; then
|
|
echo "pid $(<$pidfile) still running"
|
|
rc_failed
|
|
else
|
|
> $pidfile
|
|
/bin/su -p -s /bin/bash $USER $KIBANA_BIN &> $LOG_PATH/kibana-init.log &
|
|
fi
|
|
|
|
# Remember status and be verbose
|
|
rc_status -v
|
|
;;
|
|
stop)
|
|
echo -n "Shutting down $name "
|
|
pid=$(<$pidfile)
|
|
rm $pidfile 2>/dev/null
|
|
kill -TERM $pid 2>/dev/null
|
|
|
|
# Remember status and be verbose
|
|
rc_status -v
|
|
;;
|
|
restart)
|
|
## Stop the service and regardless of whether it was
|
|
## running or not, start it again.
|
|
$0 stop
|
|
$0 start
|
|
|
|
# Remember status and be quiet
|
|
rc_status
|
|
;;
|
|
reload)
|
|
echo -n "Reload $name "
|
|
## service does not support reload:
|
|
rc_failed 3
|
|
rc_status -v
|
|
;;
|
|
status)
|
|
echo -n "Checking for $name "
|
|
if ! [ -f $pidfile ]; then
|
|
# not running
|
|
rc_failed 3
|
|
elif [ -s $pidfile -a -d /proc/$(<$pidfile) ]; then
|
|
# running
|
|
:
|
|
else
|
|
# stale pid file
|
|
rc_failed 1
|
|
#rm -f $pidfile
|
|
fi
|
|
rc_status -v
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|status|restart|reload}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
rc_exit
|