Shutting down mongod & vagrant cleanly

What steps should be taken to cleanly shutdown the mongod, and vagrant box?

Let’s say that to complete the lab “Launching Mongod”, I use the various commands, including vagrant up, vagrant ssh, and the lab-specific mongod command, and validation.

Now how do I close everything down elegantly?

It depends on the purpose.

  1. If you want a clean slate, then just vagrant destroy followed by vagrant up
  2. If you want to hibernate or shutdown the machine for later use, then look into vagrant suspend and vagrant halt
  3. If you just want to shutdown mongod, then it’s db.shutdownServer() on the admin db
  4. If you want to remove the actions from a specific lab, then it’s a manual process of shutting down all the running mongod instances and delete all the sub-directories used to store data and log files.

Hi @Michael_27198,

For shutting down the mongod or mongos process elegantly, you can do the following :

use admin


If you want to shutdown the running virtual machine managed by vagrant you can use this command.

vagrant halt

This will power off your machine. If in case you want to put it in the sleep/suspend mode, please run the following command.

vagrant suspend

Hope it helps!

If you have any other query then please feel free to get back to us.

Happy Learning :slight_smile:

Shubham Ranjan
Curriculum Support Engineer

Thank you! Are there potential risks with not shutting down the running virtual machine?

When I try to run vagrant halt (or suspend), I get

“The program ‘vagrant’ is currently not installed. To run ‘vagrant’ please ask your administrator to install the package ‘vagrant’”

I’m puzzled by this dialog, because I do run vagrant up --provision and vagrant ssh with no problem. So far, I’ve been shutting down the server with use admin > db.shutdownServer(), but then just closing my cmd window.

I’m tried running vagrant halt directly after db.shutdownServer(), but feel like I’m still in the Mongo shell - I get a

SyntaxError: missing ; before statement @(shell)…

If I instead execute quit() after db.shutdownServer(), and then execute vagrant halt, then I get the message listed above (‘vagrant’ is currently not installed).

No! It’s not a work machine so even if anything were to go wrong, you can just fire it up again.

Let’s see a screenshot of this. And let’s also see a screenshot of when you successfully run vagrant up.

I’m not sure what you’re looking for exactly in the screenshot of vagrant up, so here is the beginning up to “Machine booted and ready!”


From here, I decided to try vagrant halt directly. It worked. That lead me to believe that the problem was that I was trying to call vagrant halt within the vagrant machine itself. So I opened up a new cmd and ran vagrant halt and it worked - so I think that solves my problem. Thanks for your help!

By asking you for a screenshot, this is what I was trying to ascertain.

Glad it’s working as expected.

1 Like

Thanks @007_jb.

Hi @Michael_27198,

Yes, you are supposed to run all the Vagrant related command on your host machine and not inside the Virtual Machine that Vagrant is managing.

Please confirm that your issue has been resolved so that I can close this thread.

Shubham Ranjan
Curriculum Services Engineer

Confirming the issue has been resolved.

Closing the thread as the issue has been resolved.