mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
132 lines
2.6 KiB
Bash
Executable file
132 lines
2.6 KiB
Bash
Executable file
#! /bin/sh
|
|
#
|
|
# /etc/rc.d/init.d/logstash
|
|
#
|
|
# Starts Logstash as a daemon
|
|
#
|
|
# chkconfig: 2345 90 10
|
|
# description: Starts Logstash as a daemon.
|
|
|
|
### 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.
|
|
### END INIT INFO
|
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
NAME=logstash
|
|
DESC="Logstash Daemon"
|
|
DEFAULT=/etc/sysconfig/$NAME
|
|
|
|
if [ `id -u` -ne 0 ]; then
|
|
echo "You need root privileges to run this script"
|
|
exit 1
|
|
fi
|
|
|
|
# The following variables can be overwritten in $DEFAULT
|
|
PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
|
|
|
# See contents of file named in $DEFAULT for comments
|
|
LS_USER=logstash
|
|
LS_GROUP=logstash
|
|
LS_HOME=/var/lib/logstash
|
|
LS_HEAP_SIZE="1g"
|
|
LS_LOG_FILE=/var/log/logstash/$NAME.log
|
|
LS_CONF_DIR=/etc/logstash/conf.d
|
|
LS_OPEN_FILES=16384
|
|
LS_NICE=19
|
|
LS_OPTS=""
|
|
LS_PIDFILE=/var/run/$NAME/$NAME.pid
|
|
|
|
# End of variables that can be overwritten in $DEFAULT
|
|
|
|
if [ -f "$DEFAULT" ]; then
|
|
. "$DEFAULT"
|
|
fi
|
|
|
|
# Define other required variables
|
|
PID_FILE=${LS_PIDFILE}
|
|
|
|
DAEMON="/opt/logstash/bin/logstash"
|
|
DAEMON_OPTS="-f ${LS_CONF_DIR} -l ${LS_LOG_FILE} ${LS_OPTS}"
|
|
|
|
#
|
|
# Function that starts the daemon/service
|
|
#
|
|
do_start()
|
|
{
|
|
|
|
if [ -z "$DAEMON" ]; then
|
|
echo "not found - $DAEMON"
|
|
exit 1
|
|
fi
|
|
|
|
if pidofproc -p "$PID_FILE" >/dev/null; then
|
|
exit 0
|
|
fi
|
|
|
|
# Prepare environment
|
|
HOME="${HOME:-$LS_HOME}"
|
|
LS_JAVA_OPTS="${LS_JAVA_OPTS} -Djava.io.tmpdir=${LS_HOME}"
|
|
ulimit -n ${LS_OPEN_FILES}
|
|
cd "${LS_HOME}"
|
|
export PATH HOME LS_HEAP_SIZE LS_JAVA_OPTS LS_USE_GC_LOGGING LS_GC_LOG_FILE
|
|
test -n "${JAVACMD}" && export JAVACMD
|
|
|
|
nice -n ${LS_NICE} runuser -s /bin/sh -c "exec $DAEMON $DAEMON_OPTS" ${LS_USER} >> $LS_LOG_FILE 2>&1 < /dev/null &
|
|
|
|
RETVAL=$?
|
|
local PID=$!
|
|
# runuser forks rather than execing our process.
|
|
usleep 500000
|
|
JAVA_PID=$(ps axo ppid,pid | awk -v "ppid=$PID" '$1==ppid {print $2}')
|
|
PID=${JAVA_PID:-$PID}
|
|
echo $PID > $PID_FILE
|
|
[ "$PID" = "$JAVA_PID" ] && success
|
|
}
|
|
|
|
#
|
|
# Function that stops the daemon/service
|
|
#
|
|
do_stop()
|
|
{
|
|
killproc -p $PID_FILE $DAEMON
|
|
RETVAL=$?
|
|
echo
|
|
[ $RETVAL = 0 ] && rm -f ${PID_FILE}
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
echo -n "Starting $DESC: "
|
|
do_start
|
|
touch /var/run/logstash/$NAME
|
|
;;
|
|
stop)
|
|
echo -n "Stopping $DESC: "
|
|
do_stop
|
|
rm /var/run/logstash/$NAME
|
|
;;
|
|
restart|reload)
|
|
echo -n "Restarting $DESC: "
|
|
do_stop
|
|
do_start
|
|
;;
|
|
status)
|
|
echo -n "$DESC"
|
|
status -p $PID_FILE
|
|
exit $?
|
|
;;
|
|
*)
|
|
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
|
|
exit 3
|
|
;;
|
|
esac
|
|
|
|
echo
|
|
exit 0
|