MongoDB: Turn off service

Source: Internet
Author: User
The MongoDB provides several commands for shutting down the service, specifically the following:


one use crtl+c off

[MONGO@REDHATB data]$ mongod--dbpath=/database/mongodb/data/--logpath=/var/applog/mongo_log/mongo.log--logappend --port=27017--journal > Start_mongo.log 2>&1
Cursors: Typing crtl+c off
Note: If you start the MongoDB service in front of the desk, the "crtl+c" service will be turned off, which will wait
The currently ongoing operation is complete, so it is still a clean shutdown.

Two use database command shutdown
--2.1 Open Service

[MONGO@REDHATB data]$ mongod-f/database/mongodb/data/mongodb_27017.conf
Forked process:18155
All output going to:/var/applog/mongo_log/mongo.log
Child process started successfully, parent exiting

--2.2 Login Database

[MONGO@REDHATB data]$ MONGO
MongoDB Shell version:2.2.1
Connecting To:test

--2.3 shutdown MongoDB Service

> Use Admin;
Switched to DB admin

> db.shutdownserver ();
Wed Nov 06:07:33 Dbclientcursor::init call () failed
Wed Nov 06:07:33 Query failed:admin. $cmd {shutdown:1.0} to:127.0.0.1:27017
Server should is down ...
Wed Nov 06:07:33 trying reconnect to 127.0.0.1:27017
Wed Nov 06:07:33 Reconnect 127.0.0.1:27017 failed couldnt connect to server 127.0.0.1:27017

three uses the Mongod command to close

[MONGO@REDHATB data]$ mongod --shutdown --dbpath/database/mongodb/data/
Killing process with pid:17747
Note: The shutdown option for the Mongod command can cleanly close the MongoDB service.

Four use KILL command
--4.1 view MONGO related processes

[MONGO@REDHATB data]$ Ps-ef | grep MONGO
Root 17573 14213 0 05:10 pts/1 00:00:00 Su-mongo
MONGO 17574 17573 0 05:10 pts/1 00:00:00-bash
MONGO 18288 1 0 06:12? 00:00:00 mongod-f/database/mongodb/data/mongodb_27017.conf
MONGO 18300 17574 6 06:13 pts/1 00:00:00 ps-ef
MONGO 18301 17574 0 06:13 pts/1 00:00:00 grep MONGO

--4.2 Kill MONGO Service process

[MONGO@REDHATB data]$ Kill 18288

[MONGO@REDHATB data]$ Ps-ef | grep Pmon
MONGO 18304 17574 0 06:13 pts/1 00:00:00 grep pmon

Note: You can use the operating system kill command to send a SIGINT or sigterm signal to the mongod process.
That is, "Kill-2 pid," or "kill-15 pid".

It is recommended that you do not use "kill-9 pid" because if MongoDB is running without opening the log (--journal),
Data loss may be caused.

Five references
Http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo
http://docs.mongodb.org/manual/reference/mongod/
Http://www.cnblogs.com/taobataoma/archive/2007/08/30/875743.html
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.