Skip to content

Instantly share code, notes, and snippets.

@chaozh
Created March 5, 2017 02:21
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 chaozh/b757babb55134b5d13f8ae1912a495bc to your computer and use it in GitHub Desktop.
Save chaozh/b757babb55134b5d13f8ae1912a495bc to your computer and use it in GitHub Desktop.
mongodb在init.d下服务化脚本
#!/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