Created
March 5, 2017 02:21
-
-
Save chaozh/b757babb55134b5d13f8ae1912a495bc to your computer and use it in GitHub Desktop.
mongodb在init.d下服务化脚本
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 | |
# chkconfig: 35 85 15 | |
# description: Mongo is a scalable, document-oriented database. | |
# processname: mongod | |
# config: /etc/mongod.conf | |
# pidfile: /var/run/mongo/mongo.pid | |
. /etc/rc.d/init.d/functions | |
MONGOHOME="/usr/local/mongodb" | |
CONFIGFILE="/etc/mongod.conf" | |
DBPATH=`awk -F= '/^dbpath[ ]*=/{print $2}' "$CONFIGFILE" |sed -e 's/^[ ]*//'` | |
COMMAND="$MONGOHOME/bin/mongod" | |
OPT="--config $CONFIGFILE" | |
mongod=${MONGOD-$COMMAND} | |
usage() { | |
echo "Usage: $0 {start|stop|restart|status}" | |
exit 0 | |
} | |
if [ $# != 1 ]; then | |
usage | |
fi | |
start() | |
{ | |
echo -n $"Starting mongod: " | |
daemon $COMMAND $OPT | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod | |
} | |
stop() | |
{ | |
echo -n $"Stopping mongod: " | |
killproc -p "$DBPATH"/mongod.lock -d 300 "$COMMAND" | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
status) | |
status $mongod | |
RETVAL=$? | |
;; | |
* ) | |
usage | |
;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment