MongoDB
Start Mongo as a service - chkconfig
This chapter will explain how to setup mongod service on CentOS 6.5 : # service mongod start | stop | restart
1. If old rc.d script exists remove it with: #chkconfig --del mongod
2. #cd /etc/rc.d/init.d/
3. Rename or remove old script: # mv mongod mongod_bak
4. Create new script: # vim mongod
#!/bin/sh
#
# Note runlevel 2345, 86 is the Start order and 85 is the Stop order
#
# chkconfig: 2345 86 85
# description: Description of the Service
#
#Source function library
. /etc/init.d/functions
start(){
mongod --config /etc/mongod.conf
}
stop(){
mongod --shutdown --config /etc/mongod.conf
}
restart(){
mongod --shutdown --config /etc/mongod.conf
mongod --config /etc/mongod.conf
}
case "$1" in
start)
echo "Start service mongod"
start
;;
stop)
echo "Stop service mongod"
stop
;;
restart)
echo "Restart service mongod"
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
5. Set exe permissions to file:
# chmod a+x mongod
6. Add service: # chkonfig --add mongod
7. Check if everything is ok:
# chkconfig | grep mongod
mongod 0:off 1:off 2:on 3:on 4:on 5:on 6:off
8. Now you can use commands: # service mongod start | stop | restart . Also, MongoDB will be started automatically on reboot.