MongoDB Service Monitoring script (start service) under Linux _linux

Source: Internet
Author: User
Tags mongodb

A few days ago, a development colleague found me saying that the mongodb of his test environment often hung up and asked me to write a monitor or resurrection script. I think it is strange that the test environment is not a load, often hanging off must have unconventional reasons.
Ran past looked at the log, found that there is a stop record, I was puzzled, no one to operate his own stop. This is obviously not dead, so went to history to see the next colleague's start command:

Copy Code code as follows:

/usr/local/mongodb/bin/mongod--dbpath=/usr/local/mongodb/data/--logpath=/data/mongodb.log--logappend &

I see! Because he did not start with nohup, so as long as his terminal offline or shut down, MongoDB will automatically quit! The solution is simple, starting with the following:

Copy Code code as follows:

Nohup/usr/local/mongodb/bin/mongod--dbpath=/usr/local/mongodb/data/--logpath=/data/mongodb.log--logappend >/ Dev/null 2>&1 &

It's hard to knock orders, so it's much more comfortable to find a MongoDB service script from the Internet:

#!/bin/sh # #mongod-startup script for Mongod # chkconfig:-description:mongodb database. # processname:mongod # Source function library. /etc/rc.d/init.d/functions # Things from mongod.conf to there by Mongod reading it # options options= '--dbpath=/home/dat a/mongodb/--logpath=/home/data/mongodb/mongodb.log--logappend & "#mongod mongod="/usr/local/mongodb/bin/
 Mongod "Lockfile=/var/lock/subsys/mongod start () {echo-n $" starting Mongod: Daemon $mongod $OPTIONS retval=$? echo [$RETVAL-eq 0] && Touch $lockfile} stop () {echo-n $ "stopping Mongod: Killproc $mongod-quit RET
 Val=$? echo [$RETVAL-eq 0] && rm-f $lockfile} restart () {Stop start} ulimit-n 12000 retval=0 case "
 "in Start" start;;
 stop) stop;;
 restart|reload|force-reload) restart;; Condrestart) [f $lockfile] && Restart | |
 :
  ;;
  Status $mongod retval=$?
 ;; *) echo "Usage: $ {start|stop|status|resTart|reload|force-reload|condrestart} "retval=1 Esac exit $RETVAL 

Save the code to/ETC/INIT.D/MONGODB, and then use chmod +x/etc/init.d/mongodb to add execution permissions.
Now, you can use the Service command to control MongoDB:

Copy Code code as follows:

Service MongoDB Start|stop|restart
#或
/etc/init.d/mongodb Start|stop|restart

Very simple, posted to the blog to record, in case of a rainy moment.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.