mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
Update logstash.init
Fixed the init.d script. Example taken from: https://github.com/mhorbul/logstash-rpm/
This commit is contained in:
parent
55fbc55b9f
commit
9ee2f2b3fe
1 changed files with 62 additions and 139 deletions
|
@ -1,157 +1,80 @@
|
||||||
#! /bin/sh
|
#!/bin/bash
|
||||||
#
|
# chkconfig: - 80 15
|
||||||
# /etc/rc.d/init.d/logstash
|
|
||||||
#
|
|
||||||
# Starts Logstash as a daemon
|
|
||||||
#
|
|
||||||
# chkconfig: 2345 20 80
|
|
||||||
# description: Starts Logstash as a daemon
|
|
||||||
|
|
||||||
### BEGIN INIT INFO
|
### BEGIN INIT INFO
|
||||||
# Provides: logstash
|
# Provides: logstash
|
||||||
# Required-Start: $local_fs $remote_fs
|
# Required-Start: $all
|
||||||
# Required-Stop: $local_fs $remote_fs
|
# Required-Stop: $all
|
||||||
# Default-Start: 2 3 4 5
|
# Default-Start:
|
||||||
# Default-Stop: S 0 1 6
|
# Default-Stop: 0 1 6
|
||||||
# Short-Description: Logstash
|
# Short-Description: Starts logstash
|
||||||
# Description: Starts Logstash as a daemon.
|
# Description: Logstash agent
|
||||||
|
|
||||||
### END INIT INFO
|
### END INIT INFO
|
||||||
|
|
||||||
|
# Source function library.
|
||||||
. /etc/rc.d/init.d/functions
|
. /etc/rc.d/init.d/functions
|
||||||
|
|
||||||
PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
NAME=@@@NAME@@@
|
||||||
NAME=logstash
|
|
||||||
DESC="Logstash Daemon"
|
|
||||||
DEFAULT=/etc/sysconfig/$NAME
|
|
||||||
|
|
||||||
if [ `id -u` -ne 0 ]; then
|
[ -f /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
|
||||||
echo "You need root privileges to run this script"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# The following variables can be overwritten in $DEFAULT
|
LOGSTASH_USER=${NAME}
|
||||||
|
DAEMON="@@@DAEMON@@@/${NAME}"
|
||||||
|
SERVICE=agent
|
||||||
|
|
||||||
export JAVA_HOME=/usr
|
PID_FILE=${PIDFILE:-@@@PIDDIR@@@/${NAME}.pid}
|
||||||
|
LOCK_FILE=${LOCKFILE:-@@@LOCKFILE@@@}
|
||||||
|
LOG_FILE=${LOGFILE:-@@@LOGDIR@@@/${NAME}.log}
|
||||||
|
|
||||||
# Directory where the logstash all in one jar lives
|
LOGSTASH_PATH_CONF=${LOGSTASH_PATH_CONF:-@@@CONFDIR@@@}
|
||||||
LS_HOME=/usr/share/logstash
|
LOGSTASH_LOGLEVEL=${LOGSTASH_LOGLEVEL:-"warn"}
|
||||||
|
|
||||||
# Additional Java OPTS
|
DAEMON_OPTS="\
|
||||||
LS_JAVA_OPTS="-Xmx256m -Djava.io.tmpdir=$LS_HOME/tmp"
|
-P ${PID_FILE} \
|
||||||
|
-l ${LOG_FILE} \
|
||||||
|
-f ${LOGSTASH_PATH_CONF} \
|
||||||
|
-v $LOGSTASH_LOGLEVEL \
|
||||||
|
"
|
||||||
|
|
||||||
# logstash log directory
|
start() {
|
||||||
LOG_DIR=/var/log/logstash
|
echo -n $"Starting ${NAME}: "
|
||||||
|
export JAVA_OPTS="$JAVA_OPTS $LOGSTASH_JAVA_OPTS"
|
||||||
# logstash configuration directory
|
daemon --pidfile=${PID_FILE} --user $LOGSTASH_USER $DAEMON $SERVICE $DAEMON_OPTS
|
||||||
CONF_DIR=/etc/logstash/conf.d
|
|
||||||
|
|
||||||
# logstash log file
|
|
||||||
LOG_FILE=$LOG_DIR/$NAME.log
|
|
||||||
|
|
||||||
# Open File limit
|
|
||||||
OPEN_FILES=2048
|
|
||||||
|
|
||||||
# Nice level
|
|
||||||
NICE=19
|
|
||||||
|
|
||||||
# Filter threads
|
|
||||||
FILTER_THREADS=1
|
|
||||||
|
|
||||||
# End of variables that can be overwritten in $DEFAULT
|
|
||||||
|
|
||||||
if [ -f "$DEFAULT" ]; then
|
|
||||||
. "$DEFAULT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Define other required variables
|
|
||||||
PID_FILE=/var/run/$NAME.pid
|
|
||||||
|
|
||||||
JAVA=`which java`
|
|
||||||
JAR="${LS_HOME}/logstash.jar"
|
|
||||||
ARGS="${LS_JAVA_OPTS} -jar ${JAR} agent --config ${CONF_DIR} --log ${LOG_FILE} -w ${FILTER_THREADS}"
|
|
||||||
|
|
||||||
is_true() {
|
|
||||||
if [ "x$1" = "xtrue" -o "x$1" = "xyes" -o "x$1" = "x1" ] ; then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Function that starts the daemon/service
|
|
||||||
#
|
|
||||||
do_start()
|
|
||||||
{
|
|
||||||
|
|
||||||
if ! is_true "$START" ; then
|
|
||||||
echo "logstash not configured to start, please edit $DEFAULT to enable"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$JAVA" ]; then
|
|
||||||
echo "no JDK found - $JAVA"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! test -e "${JAR}"; then
|
|
||||||
echo "Daemon $DAEMON doesn't exist"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if pidofproc -p "$PID_FILE" >/dev/null; then
|
|
||||||
failure
|
|
||||||
exit 99
|
|
||||||
fi
|
|
||||||
|
|
||||||
ulimit -n $OPEN_FILES
|
|
||||||
|
|
||||||
cd $LS_HOME
|
|
||||||
$JAVA $ARGS > /dev/null 1>&1 &
|
|
||||||
|
|
||||||
RETVAL=$?
|
|
||||||
local PID=`pgrep -f "${DAEMON} ${ARGS}"`
|
|
||||||
echo $PID > $PID_FILE
|
|
||||||
success
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Function that stops the daemon/service
|
|
||||||
#
|
|
||||||
do_stop()
|
|
||||||
{
|
|
||||||
killproc -p $PID_FILE $DAEMON
|
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
echo
|
echo
|
||||||
[ $RETVAL = 0 ] && rm -f ${PID_FILE}
|
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
|
||||||
|
return $RETVAL
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
|
||||||
|
echo -n $"Stopping ${NAME}: "
|
||||||
|
killproc -p ${PID_FILE} -d 10 $DAEMON
|
||||||
|
RETVAL=$?
|
||||||
|
echo
|
||||||
|
[ $RETVAL = 0 ] && rm -f ${LOCK_FILE} ${PID_FILE}
|
||||||
|
return $RETVAL
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
echo -n "Starting $DESC: "
|
start
|
||||||
do_start
|
;;
|
||||||
touch /var/lock/subsys/logstash/$NAME
|
stop)
|
||||||
;;
|
stop
|
||||||
stop)
|
;;
|
||||||
echo -n "Stopping $DESC: "
|
status)
|
||||||
do_stop
|
status -p ${PID_FILE} $DAEMON
|
||||||
rm /var/lock/subsys/logstash/$NAME
|
RETVAL=$?
|
||||||
;;
|
;;
|
||||||
restart|reload)
|
restart|force-reload)
|
||||||
echo -n "Restarting $DESC: "
|
stop
|
||||||
do_stop
|
start
|
||||||
do_start
|
;;
|
||||||
;;
|
*)
|
||||||
status)
|
N=/etc/init.d/${NAME}
|
||||||
echo -n "$DESC"
|
echo "Usage: $N {start|stop|restart|force-reload}" >&2
|
||||||
status -p $PID_FILE
|
RETVAL=2
|
||||||
;;
|
;;
|
||||||
*)
|
|
||||||
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
|
|
||||||
exit 3
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
echo
|
exit $RETVAL
|
||||||
exit 0
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue