Created
February 3, 2010 16:05
-
-
Save emerleite/293710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: mongodb | |
# Author: Emerson Macedo - http://github.com/emerleite - http://codificando.com | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: starts the mongodb data-store | |
# Description: starts mongodb using mongod provided script | |
### END INIT INFO | |
PATH=/opt/mongodb/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
DAEMON=/opt/mongodb/bin/mongod | |
PIDFILE=/var/log/mongodb/mongodb.pid | |
LOGFILE=/var/log/mongodb/mongodb.log | |
NAME=mongodb | |
DESC=mongodb | |
test -x $DAEMON || exit 0 | |
#set -e | |
start_mongodb() { | |
if [ -f $PIDFILE ] | |
then | |
echo "$NAME already started" | |
exit 1 | |
fi | |
$DAEMON --fork --logappend --logpath $LOGFILE --bind_ip 127.0.0.1 >> $PIDFILE | |
} | |
stop_mongodb() { | |
if [ ! -f $PIDFILE ] | |
then | |
echo "$NAME is not started" | |
exit 1 | |
fi | |
kill -9 `grep -e '^forked process: [0-9]' $PIDFILE | sed 's/^forked process: //'` | |
rm -f $PIDFILE | |
} | |
case "$1" in | |
start) | |
echo "Starting $DESC: " | |
start_mongodb | |
echo "$NAME started" | |
;; | |
stop) | |
echo "Stopping $DESC: " | |
stop_mongodb | |
echo "$NAME stopped" | |
;; | |
restart|force-reload) | |
echo -n "Restarting $DESC: " | |
stop_mongodb | |
sleep 1 | |
start_mongodb | |
echo "$NAME restarted" | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
echo "Usage: $N {start|stop|restart|force-reload}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment