Skip to content

Instantly share code, notes, and snippets.

@rtgibbons
Created November 23, 2011 19:24
Show Gist options
  • Save rtgibbons/1389633 to your computer and use it in GitHub Desktop.
Save rtgibbons/1389633 to your computer and use it in GitHub Desktop.
Centos init.d for mms-agent from 10Gen
#!/bin/bash
#
# /etc/rc.d/init.d/mms-agent
#
# 10Gen Mongod montiroing service
# must edit the settings.py first and edit this file with the location of agent.py
#
# description: 10Gen monitoring service - need ot fix pid so we can shut it down
# chkconfig: - 90 10
# Source function library.
. /etc/init.d/functions
prog="mms-agent"
python="/usr/local/bin/python2.7"
agent="/usr/local/lib/mms-agent/agent.py"
logfile="/var/log/mongodb/$prog.log"
pidfile="/var/run/mongodb/$prog.pid"
start() {
echo -n "Starting $prog: "
daemon --user mongodb --pidfile $pidfile "$python $agent > $logfile 2>&1 &"
retval=$?
pid=$$
[ $retval -eq 0 ] && touch /var/lock/subsys/$prog
return $retval
}
stop() {
#doesn't work at the moment
echo -n "Shutting down $prog: "
killproc -p $pidfile $prog
retval=$?
[ $retval -eq 0 ] && rm -f /var/lock/subsys/$prog
return $retval
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
*)
echo "Usage: <servicename> {start|stop|reload|restart}"
exit 1
;;
esac
exit $?
@6d61726b760a
Copy link

suggested additions for pid file:

start() {
        echo -n "Starting $prog: "
        daemon --pidfile $pidfile "$python $agent > $logfile 2>&1 &"
        /usr/bin/pgrep -f $agent > $pidfile
        retval=$?
        pid=$$
        [ $retval -eq 0 ] && /bin/touch /var/lock/subsys/$prog
        return $retval

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment