Skip to content

Instantly share code, notes, and snippets.

@Cryptophobia
Last active January 25, 2021 08:39
Show Gist options
  • Save Cryptophobia/79720359d3cf547dd32172efb3bc4acf to your computer and use it in GitHub Desktop.
Save Cryptophobia/79720359d3cf547dd32172efb3bc4acf to your computer and use it in GitHub Desktop.
/etc/init.d/fluentd
#!/bin/bash
NAME="fluentd" #Name of service
PID_FILE=/var/run/fluentd.pid #PID file for fluentd service
CONF_FILE=/etc/fluent/fluent.conf #Config file for fluentd service
LOG_FILE=/var/log/fluent/fluent.log #Log file for fluentd process
PSNAME="fluentd" #Process to look for in ps output
RVM_PATH=home/ubuntu/.rvm/scripts/rvm #RVM path to source because RVM is awesome
RUBY_VER="default" #RVM default ruby version, you can set to specific Ruby verion
status() {
echo -n "Checking $NAME service..."
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
echo "$NAME is not running but pidfile exists."
return 1
else
echo "$NAME service is running."
return 0
fi
else
echo "$NAME service not running."
return 1
fi
}
start() {
if [ -f "$PID_FILE" ] && kill -0 $(cat "$PID_FILE"); then
echo "$NAME service already running." >&2
return 1
fi
echo -n "Starting $NAME service..." >&2
source $RVM_PATH
rvm use $RUBY_VER
export rvmsudo_secure_path=1
`rvmsudo fluentd --daemon $PID_FILE --config $CONF_FILE --log $LOG_FILE -vv`
echo "$NAME service started." >&2
}
stop() {
if [ ! -f "$PID_FILE" ] || ! kill -0 $(cat "$PID_FILE"); then
echo "$NAME service not running." >&2
return 1
fi
echo -n "Stopping $NAME service..." >&2
kill -15 $(cat "$PID_FILE") && rm -f "$PID_FILE"
echo "$NAME service stopped." >&2
}
case "$1" in
status)
status
;;
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {status|start|stop|restart}"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment