Skip to content

Instantly share code, notes, and snippets.

@stevenrombauts
Last active August 29, 2015 14:07
Show Gist options
  • Save stevenrombauts/4b1969c1b3692bcdacac to your computer and use it in GitHub Desktop.
Save stevenrombauts/4b1969c1b3692bcdacac to your computer and use it in GitHub Desktop.
init.d script to manage New Relic MySQL plugin (java)
#!/bin/bash
### BEGIN INIT INFO
# Provides: newrelic-mysql
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Start/stop New Relic MySQL plugin
### END INIT INFO
DIR=/root/newrelic_mysql_plugin-2.0.0
NAME=newrelic-mysql
PID=/var/run/$NAME.pid
JAVA=/usr/bin/java
JAVA_OPTS="-Xmx128m -server -jar plugin.jar"
LOG=/var/log/$NAME.log
USER=www-data
case $1 in
start)
echo -n "Starting $NAME ... "
if [ ! -f $PID ]; then
cd $DIR
nohup $JAVA $JAVA_OPTS 2>&1 > $LOG &
PROCESS_ID=$!
if kill -0 $PROCESS_ID > /dev/null 2>&1; then
echo $PROCESS_ID > $PID
echo ".. OK (pid $PROCESS_ID)"
else
echo "failed to start $NAME!"
fi
else
echo "$NAME is already running!"
fi
;;
stop)
if [ -f $PID ]; then
PROCESS_ID=$(cat $PID);
echo "Stopping $NAME (pid $PROCESS_ID) ..."
kill $PROCESS_ID
rm $PID
else
echo "$NAME is not running ..."
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment