Skip to content

Instantly share code, notes, and snippets.

@drfeelngood
Created August 2, 2011 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drfeelngood/1120590 to your computer and use it in GitHub Desktop.
Save drfeelngood/1120590 to your computer and use it in GitHub Desktop.
mongod service script
#!/bin/bash
# mongod
#
# chkconfig: 2345
# description: Scalable, high-performance, open source, document-oriented
# database. Written in C++.
#
# processname: mongod
# pidfile: /var/run/mongod.pid
# config: /etc/mongod.conf
. /etc/init.d/functions # Source function library.
EXE=/opt/mongodb/bin/mongod
CONF=/etc/mongod.conf
PIDFILE=/var/run/mongod.pid
prog="mongod"
start()
{
if [ -f $PIDFILE ]; then
ret=0
echo "$PIDFILE exists, process already running."
else
$EXE --config $CONF --pidfilepath $PIDFILE > /dev/null
ret=$?
fi
if [ $ret -eq 0 ]; then
action $"Starting $prog: " /bin/true
else
action $"Starting $prog: " /bin/false
fi
return $ret
}
stop()
{
if [ ! -f $PIDFILE ]; then
ret=1
echo "$PIDFILE does not exist."
else
PID=$(cat $PIDFILE)
if [ -n $PID ]; then
`kill -2 $PID`
ret=$?
echo -n "Waiting for $prog to stop "
while [ -x /proc/${PID} ]; do
echo -n "."
sleep 1
done
echo
rm $PIDFILE
else
ret=1
echo "$PID does not exist."
fi
fi
if [ $ret -eq 0 ]; then
action $"Stopping $prog: " /bin/true
else
action $"Stopping $prog: " /bin/false
fi
return $ret
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status $prog
;;
*)
echo "Usage: $0 (start|stop|restart|status)"
exit 1
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment