mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -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
|
||||
#
|
||||
# /etc/rc.d/init.d/logstash
|
||||
#
|
||||
# Starts Logstash as a daemon
|
||||
#
|
||||
# chkconfig: 2345 20 80
|
||||
# description: Starts Logstash as a daemon
|
||||
|
||||
#!/bin/bash
|
||||
# chkconfig: - 80 15
|
||||
### BEGIN INIT INFO
|
||||
# Provides: logstash
|
||||
# Required-Start: $local_fs $remote_fs
|
||||
# Required-Stop: $local_fs $remote_fs
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: S 0 1 6
|
||||
# Short-Description: Logstash
|
||||
# Description: Starts Logstash as a daemon.
|
||||
|
||||
# Provides: logstash
|
||||
# Required-Start: $all
|
||||
# Required-Stop: $all
|
||||
# Default-Start:
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Starts logstash
|
||||
# Description: Logstash agent
|
||||
### END INIT INFO
|
||||
|
||||
# Source function library.
|
||||
. /etc/rc.d/init.d/functions
|
||||
|
||||
PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
||||
NAME=logstash
|
||||
DESC="Logstash Daemon"
|
||||
DEFAULT=/etc/sysconfig/$NAME
|
||||
NAME=@@@NAME@@@
|
||||
|
||||
if [ `id -u` -ne 0 ]; then
|
||||
echo "You need root privileges to run this script"
|
||||
exit 1
|
||||
fi
|
||||
[ -f /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
|
||||
|
||||
# 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
|
||||
LS_HOME=/usr/share/logstash
|
||||
LOGSTASH_PATH_CONF=${LOGSTASH_PATH_CONF:-@@@CONFDIR@@@}
|
||||
LOGSTASH_LOGLEVEL=${LOGSTASH_LOGLEVEL:-"warn"}
|
||||
|
||||
# Additional Java OPTS
|
||||
LS_JAVA_OPTS="-Xmx256m -Djava.io.tmpdir=$LS_HOME/tmp"
|
||||
DAEMON_OPTS="\
|
||||
-P ${PID_FILE} \
|
||||
-l ${LOG_FILE} \
|
||||
-f ${LOGSTASH_PATH_CONF} \
|
||||
-v $LOGSTASH_LOGLEVEL \
|
||||
"
|
||||
|
||||
# logstash log directory
|
||||
LOG_DIR=/var/log/logstash
|
||||
|
||||
# logstash configuration directory
|
||||
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
|
||||
start() {
|
||||
echo -n $"Starting ${NAME}: "
|
||||
export JAVA_OPTS="$JAVA_OPTS $LOGSTASH_JAVA_OPTS"
|
||||
daemon --pidfile=${PID_FILE} --user $LOGSTASH_USER $DAEMON $SERVICE $DAEMON_OPTS
|
||||
RETVAL=$?
|
||||
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
|
||||
start)
|
||||
echo -n "Starting $DESC: "
|
||||
do_start
|
||||
touch /var/lock/subsys/logstash/$NAME
|
||||
;;
|
||||
stop)
|
||||
echo -n "Stopping $DESC: "
|
||||
do_stop
|
||||
rm /var/lock/subsys/logstash/$NAME
|
||||
;;
|
||||
restart|reload)
|
||||
echo -n "Restarting $DESC: "
|
||||
do_stop
|
||||
do_start
|
||||
;;
|
||||
status)
|
||||
echo -n "$DESC"
|
||||
status -p $PID_FILE
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
|
||||
exit 3
|
||||
;;
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
status)
|
||||
status -p ${PID_FILE} $DAEMON
|
||||
RETVAL=$?
|
||||
;;
|
||||
restart|force-reload)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
*)
|
||||
N=/etc/init.d/${NAME}
|
||||
echo "Usage: $N {start|stop|restart|force-reload}" >&2
|
||||
RETVAL=2
|
||||
;;
|
||||
esac
|
||||
|
||||
echo
|
||||
exit 0
|
||||
exit $RETVAL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue