Last active
January 4, 2016 01:49
-
-
Save NoodlesNZ/8550466 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# /etc/init.d/logstash-forwarder | |
# | |
# Starts and stops logstash-forwader as a "daemon". | |
# | |
# chkconfig: 2345 30 70 | |
# description: Starts and stops logstash-forwarder as a daemon. | |
# The name of this service | |
NAME=logstash-forwarder | |
### Start Configuration Options ### | |
# The JSON config to use | |
LSF_CONFIG=/etc/logstash-forwarder.conf | |
# The logstash-forwarder binary | |
LSF_BIN=/opt/logstash-forwarder/bin/logstash-forwarder | |
# Any logstash-forwarder options | |
LSF_OPTS="-spool-size 1000" | |
# The log file for local info | |
LSF_LOG=/var/log/logstash-forwarder | |
# The PID file | |
PID_FILE=/var/run/logstash-forwarder.pid | |
# The command to daemonize | |
DAEMON="nohup ${LSF_BIN} -config ${LSF_CONFIG} ${LSF_OPTS} >>${LSF_LOG} 2>&1 &" | |
### End Configuration Options ### | |
. /etc/init.d/functions | |
check_prereqs() { | |
if [ ! -f ${LSF_CONFIG} ]; then | |
echo "ERROR: LSF_CONFIG (${LSF_CONFIG}) doesn't exist." | |
exit 1 | |
elif [ ! -d `dirname ${LSF_LOG}` ]; then | |
echo "ERROR: LSF_LOG parent directory (`dirname ${LSF_LOG}`) doesn't exist." | |
exit 1 | |
fi | |
} | |
start() { | |
check_prereqs | |
echo -n $"Starting $NAME: " | |
daemon --check $NAME --pidfile $PID_FILE $DAEMON | |
RETVAL=$? | |
if [ $RETVAL -ne 0 ]; then | |
echo_failure | |
echo | |
else | |
PID=$(ps aux | grep -m 1 "$LSF_BIN" | awk '{print $2}') | |
echo -n $PID > $PID_FILE | |
echo_success | |
echo | |
fi | |
return $RETVAL | |
} | |
stop () { | |
echo -n $"Stopping $NAME: " | |
killproc -p $PID_FILE $NAME | |
RETVAL=$? | |
echo | |
return $RETVAL | |
} | |
restart () { | |
stop | |
start | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status -p $PID_FILE $NAME | |
;; | |
restart) | |
restart | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status}" | |
exit 2 | |
;; | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment