How to cleanly shutdown mongodb from node.js under Windows

567 views
Skip to first unread message

Andy Bisson

unread,
Mar 1, 2012, 5:29:15 AM3/1/12
to mongodb-user
I am running mongodb as an external process from node.js and I want to
be able to shut it down and restart it on demand.
If I type Ctrl-C into the shell running node.js then node.js shuts
down and mongo shuts down cleanly under it.
If I run mongoprocess.kill() from node.js then mongodb crashes out.
This is not unexpected because this sends SIGTERM which is documented
to close mongodb in an uncontrolled manner.
If I run mongoprocess.kill("SIGINT") from node.js then this also
crashes out despite assurances in the mongodb documentation that this
should cause a clean exit.
Upon restarting the mongodb process I get the following message.

mongodb_0 stdout: Thu Mar 01 09:41:15 [initandlisten] ** NOTE: when
using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Mar 01 09:41:15 [initandlisten] ** see
http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Mar 01 09:41:15 [initandlisten] ** with --journal, the limit
is lower
Thu Mar 01 09:41:15 [initandlisten]
Thu Mar 01 09:41:15 [initandlisten] db version v2.0.2, pdfile version
4.5
Thu Mar 01 09:41:15 [initandlisten] git version:
514b122d308928517f5841888ceaa4246a7f18e3
Thu Mar 01 09:41:15 [initandlisten] build info: windows (5, 1, 2600,
2, 'Service Pack 3') BOOST_LIB_VERSION=1_42
Thu Mar 01 09:41:15 [initandlisten] options: { dbpath: "C:\Users
\andrewb\Documents\Prog\IcedAPIServer\data\mongodata" }
**************
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery
instructions.
*************
Thu Mar 01 09:41:15 [initandlisten] exception in initAndListen: 12596
old lock file, terminating
Thu Mar 01 09:41:15 dbexit:
Thu Mar 01 09:41:15 [initandlisten] shutdown: going to close listening
sockets..
.
Thu Mar 01 09:41:15 [initandlisten] shutdown: going to flush
diaglog...
Thu Mar 01 09:41:15 [initandlisten] shutdown: going to close
sockets...
Thu Mar 01 09:41:15 [initandlisten] shutdown: waiting for fs
preallocator...
Thu Mar 01 09:41:15 [initandlisten] shutdown: closing all files...
Thu Mar 01 09:41:15 [initandlisten] closeAllFiles() finished
Thu Mar 01 09:41:15 dbexit: really exiting now

Is there a simple way to shut down mongodb without going via its
network interface? Is there a reason why SIGINT does not seem to work
as it should in this particular case? Clearly it works when I type
Ctrl-C.

Thanks,
Andy

Nat

unread,
Mar 1, 2012, 6:24:05 AM3/1/12
to mongod...@googlegroups.com
I'm not sure whether Node.js sends the right signal. Do you get any stacktrace when unclean shutdown happens with SIGINT?

Btw, If you log on to mongodb from Node.js anyway, why don't you issue shutdownServer command to shut down cleanly?
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Andy Bisson

unread,
Mar 1, 2012, 6:50:41 AM3/1/12
to mongodb-user
Thanks for the quick reply. Mongo doesn't seem to output anything on
stdout/stderr when it closes which would suggest that it's had the rug
pulled out from under it. Closing via the network interface is an
option but it will complicate an otherwise clean and consistent
process manager. Oh well, there's always one, and in this case I
suspect it's not actually mongodb to blame.

Nat

unread,
Mar 1, 2012, 6:56:15 AM3/1/12
to mongod...@googlegroups.com
Can you post your code? I thought you are supposed to use

process.kill(mongodbpid)

Scott Hernandez

unread,
Mar 1, 2012, 8:09:10 AM3/1/12
to mongod...@googlegroups.com
Windows doesn't use signals like that so no. You should use the
shutdown command.

Using that kill tells windows to terminate the process without warning
I believe. You could run it as a service but that requires a bit more
setup but provide hooks for startup/shutdown.

Andy Bisson

unread,
Mar 1, 2012, 9:29:08 AM3/1/12
to mongod...@googlegroups.com

This definitely seems to be the case.  I'm going to admit defeat and shutdown via the socket interface.

Thanks,
Andy 

Scott Hernandez

unread,
Mar 1, 2012, 9:43:43 AM3/1/12
to mongod...@googlegroups.com
If the node.js driver supports domain sockets you can use them but
that is basically the same as a localhost network connection.

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.

> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/Nt_KqAIdAwQJ.

Andy Bisson

unread,
Mar 1, 2012, 10:19:21 AM3/1/12
to mongod...@googlegroups.com

The next problem would appear to be how to shutdown mongodb by other means.  All of the documentation seems to revolve around the shell interface.
If I am using using the node.js driver is there a proper way to shut the server down or will I have to connect directly to the server socket to issue the shutdown command? 

Scott Hernandez

unread,
Mar 1, 2012, 10:27:54 AM3/1/12
to mongod...@googlegroups.com
In the shell, run the command without any "()" to see the implementation.

It runs the "shutdown" command (which must be run on the admin
database). http://www.mongodb.org/display/DOCS/List%20of%20database%20commands

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/mongodb-user/-/ZwY-GaMhaqAJ.

Reply all
Reply to author
Forward
0 new messages