#!/bin/bash
# chkconfig: 2345 55 25
# description: mongodb
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts mongodb
# Description: starts the mongodb
### END INIT INFO
MONGO_PATH=/www/server/mongodb
if [ ! -f $MONGO_PATH/bin/mongod ];then
echo "No installation of mognodb."
exit;
fi
Config=/www/server/mongodb/config.conf
User=mongo
start()
{
#chmod -R mongo:mongo /www/server/mongodb
sudo -u $User mongod -f $Config
}
stop()
{
sudo -u $User mongod --shutdown -f $Config
a=`ps aux|grep '/www/server/mongodb'|grep -v 'grep'|awk '{print $2}'`
if [ "$a" != "" ];then
kill -9 $a
fi
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
sleep 2
start
;;
*)
echo "Usage: /etc/init.d/mongodb {start|stop|restart}"
;;
esac
/etc/init.d/mongodb文件里就是这些内容 |