How to make a daemon for the "mongod" command

Asked

Viewed 494 times

2

What is the procedure for letting Mongo run on the server without having to use the command mongod?

Is there a specific command of Mongo for this?

  • You can probably install it as a service and run it. A curiosity: you are using linux?

  • Yes, linux on the server.

  • You need to create a user with suggestive name and program the linux so that this program runs on that user whenever the pc restarts.

  • You don’t need any of that, look at my answer. Mongo’s own manual has the solution

  • No problem Wallace Maxters. Thanks for your help.

2 answers

6


If you are using Linux, you can do the following:

nohub mongod &

Nohup will keep the process running in the background, even if you drop the server (if you are using SSH).

There is also a possibility for you to configure a service to run this command:

See here: https://stackoverflow.com/questions/19233529/run-bash-script-as-daemon

Updating

According to the Manual of the Mongodb, the correct way to do it is by using the argument --fork when rotating the command.

To run a mongod process as a daemon (i.e. Fork), and write its output to a log file, use the --Fork and --logpath options. You must create the log directory; However, mongod will create the log file if it does not exist.

Half-hearted translation:

To run a mongod process as a daemon, and write its output to a log file, use the options -=-fork and --logpath. You should create the log directory. However, mongod will create the log file if it does not exist.

To start the Mongo Daemon do:

mongod --fork --logpath /var/log/mongodb.log

Finally do:

mongod --shutdown
  • Thanks guys. It worked with mongod --Fork --logpath /var/log/mongodb.log.

  • The Log is important. Since you will not be following the output of the command in Altime, you can track errors or any other event occurred in the Log.

2

Depends on whether you are running on linux or windows?

If it is in Windows only make a bat or make it become a service and put to start together with Windows if it is in linux ai depends on which distro you are using. I’ll leave some links in the comment just for reference.

  • http://stackoverflow.com/questions/7016880/run-mongodb-server-as-a-service-detached-from-terminal

  • http://stackoverflow.com/questions/2438055/how-to-run-mongodb-as-windows-service

  • http://serverfault.com/questions/563970/how-can-i-install-mongodb-as-a-service-in-centos

  • http://askubuntu.com/questions/61503/how-to-start-mongodb-server-on-system-start

  • 2

    These references look good in the answer.

  • 1

    The right thing to do instead of doing a BAT is to use the task scheduler and create a new task that runs this application whenever Windows boots, not requiring the user to log in.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.