Fabrice Chapuis
Fabrice Chapuis

Reputation: 498

Clean shutdown of the mongod process

My mongodb run under Linux 6. I use the command db.shutdownServer() to close the database but the mongod process does not stop. Stopping mongo directly with service mongod stop do a clean shutdown?

Thanks for your help

Upvotes: 2

Views: 13525

Answers (2)

Balepur
Balepur

Reputation: 168

As per the documentation of mongodb, mongod --shutdown will work on linux system, but, on Mac, the --shutdown switch is not recognised. However, per the documentation, Ctrl+C will cleanly shutdown the db server. When you do a Ctrl+C on the same terminal where the db server is running, it initiates a dozen or so signalProcessingThread which indicates that the shutdown is proper and smooth. At the end, you can see that the process exits with code:0. Per the convention, Ctrl+C is awkward, but is clean, although not seemingly graceful.

Upvotes: 1

Andriy Simonov
Andriy Simonov

Reputation: 1288

Proper ways to shutdown mongod is described in the documentation. They are:

Use shutdownServer()
From the mongo shell
use admin
db.shutdownServer()

Use --shutdown
From the Linux command line
mongod --shutdown

Use CTRL-C
When running the mongod instance in interactive mode, issue Control-C

Use kill
From the Linux command line
kill mongoProcessID
kill -2 mongodProcessID

So you need to figure out how /etc/init.d/mongodb stop actually stops the process on your Linux distribution. For example, on Debian it uses the wrapper which behaves similar to killall which is a proper method.

Upvotes: 3

Related Questions