Skip to content

Instantly share code, notes, and snippets.

@fumi
Created June 27, 2013 01:42
Show Gist options
  • Save fumi/5873337 to your computer and use it in GitHub Desktop.
Save fumi/5873337 to your computer and use it in GitHub Desktop.
/etc/init.d/fluentd for Debian weedy
#!/bin/bash
PID_FILE=/var/run/fluent/fluent.pid
CONF_FILE=/etc/fluent/fluent.conf
LOG_FILE=/var/log/fluent/fluentd.log
PSNAME="fluentd --daemon"
F_USER=fluent
F_GROUP=fluent
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
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()
{
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