Emre K.
Emre K.

Reputation: 2815

Whats the difference between service mongodb start and mongod

When I run the command: sudo service mongodb start mongodb service starts using the default data directory.

When I run the command: mongod --dbpath data/db --fork --logpath data/log/mongodb.log

It starts mongodb with given dbpath. What is the difference?

What is actually happening when I run sudo service mongodb start first and then run mongod --dbpath data/db --fork --logpath data/log/mongodb.log

Should I stop the service first using sudo service mongodb stop?

This is all on ubuntu 12.04

Upvotes: 3

Views: 2958

Answers (2)

Arshad Ali
Arshad Ali

Reputation: 93

mongodb comes with the mongod.conf(/etc/mongod.conf) file with default configurations. when we start mongodb server using service mongodb start it takes the default params from mongod.conf and start the service, this is not the case when u start it using mongod.sh and it will take params from command line.

one more important thing to mention is lates mongodb comes with bind_ip param in mongod.conf with value 127.0.0.1, which binds the server to localhost for communication. hence mongo server is not allowed for remote network communication. but if we start server with mongod --dbpath and doesn't specify bind_ip param it will start the server communication with any network which is not recommended.

Upvotes: 0

Sammaye
Sammaye

Reputation: 43884

One uses upstart and the other doesn't, plus upstart has the benefit of being able to give advanced management of your process using a global script containing the abilities to restart/stop/start/etc the process.

When you run the service mongos uses the default configuration file you created when you installed it whereas with the direct command you are adding parameters telling mongod that it has a custom dbpath and --fork and logPath.

Upvotes: 1

Related Questions