1

I installed MongoDB in an Ubuntu Server VM inside VMware using these instructions: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/. Everything works fine, and I can access MongoDB at the regular port 27017

./mongo 172.16.150.131:27017

Now, I want to make a dummy replica set and another db instance for testing my app. I'm used to doing the following commands in four separate terminals on my local computer:

./mongod --port 27027 --dbpath ~/mongodb/solo
./mongod --port 27028 --dbpath ~/mongodb/rs0-0 --replSet rs0
./mongod --port 27029 --dbpath ~/mongodb/rs0-1 --replSet rs0
./mongod --port 27030 --dbpath ~/mongodb/rs0-2 --replSet rs0

How can I do this in the VM? I SSH into my VM, and after running the commands and closing my terminals (in OS X), they should still be running.

I tried:

service mongodb --port 27027 --dbpath ~/mongodb/solo
service mongodb ~/mongodb/solo/mongodb.conf

But both get the following error (with different contexts):

Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mongodb --config=~/mongodb/solo/mongodb.conf

The script you are attempting to invoke has been converted to an Upstart
job, but --config=~/mongodb/solo/mongodb.conf is not supported for Upstart jobs.

How do I get this working? First time working with Ubuntu as a server. Thanks.

Context - goal is to create my db in a VM to create some sort of lag while testing my app, but mostly so I can just suspend the VM instead of copying and pasting scripts into different terminals to setup MongoDB whenever I restart my laptop.

1 Answer 1

2

When you install using the Ubuntu package, it creates an upstart job and that is what you are starting/stopping with service on an Ubuntu system. Of course, it only starts one mongod and has one config by default. That upstart job can be found here (by default):

/etc/init/mongodb.conf

That is not to be confused with /etc/mongodb.conf which is the default location of the config file for the MongoDB service.

If you want to be able to start/stop the extra instances automatically or you want to have upstart manage them, then you just need to create duplicate jobs that point to different config files (or have different options specified in the job file itself). Start with taking a look at the file in init I mentioned above and then have a look here for more info on rolling your own upstart jobs:

http://upstart.ubuntu.com/cookbook/

The other option, of course, is to just invoke extra mongod instances directly. For example:

/usr/bin/mongod --fork --config=~/mongodb/solo/mongodb.conf

The --fork option (if not specified in the config file) is needed to fork to the background and not be killed when you log out and terminate the shell.

1
  • fork works perfectly. i don't really need upstart since it's just for testing and i never intend on shutting it on/off. thanks! Dec 7, 2012 at 21:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .