Keep MongoDB Windows Service running 24/7

How to Keep MongoDB Windows Service Running 24/7 with Service Protector

Monitor MongoDB and quickly auto-restart when your PC crashes or gets stuck starting/stopping. Ensure 100% uptime for your NoSQL database today!

MongoDB is a high-performance, open source NoSQL database.

To protect MongoDB with Service Protector:

  1. Download, install, and configure MongoDB as a Windows Service, if necessary.

  2. Download and install Service Protector, if necessary.

  3. Start Service Protector.

  4. Select Protector > Add to open the Add Protector window:

    Add Protector

  5. On the General tab:

    • In the Service to protect field, choose the MongoDB windows service, called Mongo DB. You will notice a green circle on the left if the MongoDB service is already running, as was the case on our server.

    • Occasionally MongoDB doesn't restart properly after a power failure, system crash or other unexpected shutdown (see bug SERVER-4373 for the details). To protect yourself against those situations, create a batch file that removes the mongodb.lock file from the db directory:

      Remove the MongoDB Lock File

      Specify that batch file in the Run this command prior to restarting the service section at the bottom of the window. This will ensure that MongoDB comes up "clean" if it ever crashes and inadvertently leaves the lock file behind.

      MongoDB Windows Service: General Tab

  6. If you find that the MongoDB windows service occasionally gets stuck in the "Stopping" or "Starting" state, click over to the Extras tab and check the corresponding options.

    MongoDB Windows Service: Extras Tab

  7. Click the Save >> button. In a second or two, an entry for MongoDB will show up in the Service Protector window. The MongoDB service is probably already running but it's not yet being monitored by Service Protector (hence the red shield).

    MongoDB Windows Service: Created

  8. To start protection, choose Protector > Start "Mongo DB". The shield icon will go to green to indicate that the MongoDB service is being protected:

    MongoDB Windows Service: Running

  9. That's it! Next time your computer boots, MongoDB will start and Service Protector will begin monitoring the service to promptly restart it if it fails.

    We encourage you to edit MongoDB in Service Protector and check out the many other settings that may be appropriate for your environment. For example, send email alerts when the service fails, restart MongoDB nightly to cure memory leaks, and much more.

Trouble protecting the MongoDB Windows Service?