Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Correct and working Logstash-forwarder init script for CentOS 5/6+
#!/bin/bash
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Kibana 4"
NAME=kibana
DAEMON=/opt/kibana/bin/$NAME
DAEMON_ARGS=""
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
LOG=/var/log/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
:
#File should be stored in the following directory with the content
#/etc/defaults/logstash-forwarder
#/etc/sysconfig/logstash-forwarder
DAEMON_ARGS="${DAEMON_ARGS:--config /etc/logstash-forwarder -spool-size 100}"
#!/bin/bash
# chkconfig: 345 80 20
# description: Logstash Forwarder
# processname: logstash-forwarder
# config: /etc/logstash-forwarder
# pidfile: /var/run/logstash-forwarder.pid
### BEGIN INIT INFO
# Provides: logstash-forwarder
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop logstash-forwarder
# Description: Logstash Forwarder
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
PATH=/sbin:/usr/sbin:/bin:/usr/bin
prog=logstash-forwarder
DAEMON=/opt/logstash-forwarder/bin/logstash-forwarder
pidfile=/var/run/$prog.pid
lockfile=/var/lock/subsys/$prog
# load defaults
[ -e /etc/default/$prog ] && . /etc/default/$prog
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
DAEMON_ARGS="${DAEMON_ARGS:--config /etc/logstash-forwarder -spool-size 100 -log-to-syslog}"
start()
{
echo -n $"Starting $prog: "
nohup $DAEMON $DAEMON_ARGS </dev/null >/dev/null 2>&1 &
retval=$?
pid=$!
echo $pid > $pidfile
if [ rh_status_q ]; then
touch $lockfile
success
echo
fi
return $retval
}
stop()
{
echo -n $"Stopping $prog: "
killproc -p "$pidfile" $prog
retval=$?
[ -f "$pidfile" ] && rm -f $pidfile
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
status -p $pidfile $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
status)
rh_status
;;
*)
echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.