-
-
Save higebu/2904183 to your computer and use it in GitHub Desktop.
/etc/init.d/fluentd
This file contains 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/bash | |
PID_FILE=/var/run/fluentd.pid | |
CONF_FILE=/etc/fluent/fluent.conf | |
LOG_FILE=/var/log/fluent/fluent.log | |
PSNAME="fluentd --daemon" | |
F_USER=fluentd | |
F_GROUP=fluentd | |
RUBY_VER="1.9.3-p194" | |
start() | |
{ | |
PID=`pgrep -f "$PSNAME"` | |
if [ -z "$PID" ]; then | |
if [ -f $PID_FILE ]; then rm -f $PID_FILE; fi | |
else | |
echo "fluentd already started." | |
return -1 | |
fi | |
if [ -z $rvm_path ]; then | |
export rvm_path=/usr/share/ruby-rvm | |
fi | |
source $rvm_path/scripts/rvm | |
rvm use $RUBY_VER 1> /dev/null | |
echo -n "Starting fluentd: " | |
fluentd --daemon $PID_FILE --user $F_USER --group $F_GROUP --config $CONF_FILE --log $LOG_FILE -vv | |
echo "done." | |
} | |
stop() | |
{ | |
PID=`pgrep -f "$PSNAME"` | |
if [ -z "$PID" ]; then | |
echo "fluentd already stopped." | |
return 0 | |
fi | |
echo -n "Stopping fluentd: " | |
pkill -TERM -f "$PSNAME" | |
count=0 | |
while [ ! -z "$PID" ]; do | |
count=`expr $count + 1` | |
if [ `expr $count % 10` == 0 ]; then pkill -KILL -f "$PSNAME"; fi | |
if [ $count == 60 ]; then | |
echo " failed." | |
return -1 | |
fi | |
sleep 1 | |
PID=`pgrep -f "$PSNAME"` | |
done | |
rm -f $PID_FILE | |
echo "done." | |
} | |
restart() | |
{ | |
stop && start | |
} | |
update() | |
{ | |
source $rvm_path/scripts/rvm | |
rvm use $RUBY_VER 1> /dev/null | |
gem update fluentd | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
restart | |
;; | |
reload) | |
pkill -HUP -f "$PSNAME" | |
;; | |
condrestart) | |
if [ ! -f $PID_FILE ]; then | |
restart | |
elif [ ! -f /proc/`cat $PID_FILE`/status ]; then | |
restart | |
fi | |
;; | |
update) | |
stop | |
update | |
start | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|reload}" | |
exit 1 | |
;; | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment