Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb shutdown option unavailable

My current problem: I have a production server and just updated mongod but lost some functionality.

In earlier versions (v2.0.6) I was able to run mongod with the --shutdown option and it would kill all other instances.

Now with version v2.4.5 - if I run:

mongod --shutdown

The result is:

error command line: unknown option shutdown
use --help for help

Version info: mongod --version

db version v2.4.5
Mon Sep 16 14:09:38.994 git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602b


It's important that I have this option or something similar to it because I have a server process that manages the new instance.

For example:

var spawn = require('child_process').spawn,
result    = spawn('mongod', ['--quiet', '--shutdown', '--directoryperdb', '--dbpath', __dirname + '/database']);


Edit:
The Mongodb documentation still has --shutdown command option.
Link: http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/

Alternately, you can shut down the mongod instance:

using the --shutdown option
from a driver using the shutdown. For details, see the drivers documentation for your driver.


Edit:
I felt I should update this question. This issue has been fixed in the mongojs wrapper as of v0.9.6. However, there are still some kinks to be worked out as listed in issue #97 but should work for most requirements.

like image 892
Levi Roberts Avatar asked Sep 16 '13 19:09

Levi Roberts


2 Answers

Since the "--shutdown" option is not available in newer versions of mongo, you now have to kill the process manually or login and run:

use admin;
db.shutdownServer();

However you can accomplish this in one line by doing:

mongo 127.0.0.1/admin --eval "db.shutdownServer()"

Assuming that you're connecting to your local db at 127.0.0.1. You can only run 1 line using the --eval param, so doing use admin; db.shutdownServer(); is not an option, however you can accomplish connecting to the admin db by adding that "/admin" after the IP.

like image 166
Scott Avatar answered Oct 01 '22 06:10

Scott


Have you tried using db.shutdownServer() in the mongo shell?

From the documentation:

To stop a mongod instance running in the background or foreground, issue the db.shutdownServer() helper in the mongo shell. Use the following sequence:

To open the mongo shell for a mongod instance running on the default port of 27017, issue the following command:

mongo

To switch to the admin database and shutdown the mongod instance, issue the following commands:

use admin
db.shutdownServer()

You may only use db.shutdownServer() when connected to the mongod when authenticated to the admin database or on systems without authentication connected via the localhost interface.


Per your comments, you can do the same thing by running the shutdown command against the admin database in a driver:

{shutdown : 1}

I'm not the most familiar with the node.js driver, but you have two options for running commands in drivers in general, and one should always work:

  1. Use your driver's wrapper for runCommand (which you can use in the mongo shell like so:)

    db.runCommand({shutdown : 1});

  2. Use the built-in $cmd pseudo-collection to run your commands. Wrappers for commands actually use this method, and if you have no other options, you can run queries against $cmd to shutdown a server:

    db.$cmd.findOne({"shutdown":1})

If you aren't running a driver, you can use the REST interface if you have it exposed (use the --rest command-line option when running mongod). By making a POST request, you can run commands against the admin database:

http://localhost:28017/admin/$cmd/?filter_shutdown=1&limit=1

which is the equivalent of running the previous query against $cmd.

like image 20
Jim Dagg Avatar answered Oct 01 '22 08:10

Jim Dagg