[root@client01 local]# cat /etc/init.d/mongod
#!/bin/sh
## chkconfig: 2345 65 38
source /etc/profile
CONFIG=/usr/local/mongodb/mongod.cnf
PROGRAM=/usr/local/mongodb/bin/mongod
MONGOPID=`ps -ef | grep 'mongod --config' | grep -v grep | awk '{print $2}'`
test -x $PROGRAM || exit 0
case "$1" in
start)
echo "Starting MongoDB Server..."
$PROGRAM --config $CONFIG &
;;
stop)
echo "Stopping MongoDB Server..."
if [ ! -z "$MONGOPID" ]; then
kill -15 $MONGOPID
fi
;;
status)
if [ -z "$MONGOPID" ]; then
echo "MongoDB is not running!"
else
echo "MongoDB is running!("$MONGOPID")"
fi
;;
restart)
echo "Shutting down MongoDB Server..."
if [ ! -z "$MONGOPID" ]; then
kill -15 $MONGOPID
fi
echo "Starting MongoDB..."
$PROGRAM --config $CONFIG &
;;
*)
log_success_msg "Usage:/etc/init.d/mongod {start|stop|status|restart}"
exit 1
esac
exit 0
mongodb配置文件:
[root@client01 local]# cat /usr/local/mongodb/mongod.cnf
logpath=/usr/local/mongodb/logs/log
logappend = true
#fork and run in background
fork = true
#port = 27017
dbpath=/usr/local/mongodb/data
#location of pidfile
pidfilepath=/usr/local/mongodb/mongod.pid
auth = true
本文转自 wjw555 51CTO博客,原文链接:http://blog.51cto.com/wujianwei/1962577