运行/停止脚本
vi /etc/init.d/mongodb
#!/bin/bash
#
# chkconfig: 2345 99 14
# description: mongodb.
CONFIG_PATH="/etc/mongodb/conf/mongodb.conf"
PIDFILE_PATH="/var/run/mongodb"
TYPE="MongoDB of Shard"
case "$1" in
start)
echo "$TYPE Start"
mkdir -p $PIDFILE_PATH
/usr/bin/mongod -f $CONFIG_PATH
;;
stop)
echo "$TYPE Stop"
/usr/bin/mongod --shutdown -f $CONFIG_PATH
;;
restart)
echo "$TYPE Restart"
/usr/bin/mongod --shutdown -f $CONFIG_PATH
/usr/bin/mongod -f $CONFIG_PATH
;;
*)
echo $"Usage: HOGE {start|stop|restart}"
esac
自动启动设置
chmod u+x /etc/init.d/mongodb
chkconfig --add /etc/init.d/mongodb
chkconfig mongodb on