4

I have a config file for mongo that specifies an alternate port:

deploy@ip-xxx-xxx-22-107 ~/app $ tail /etc/mongodb.conf
port = 27033

Not very complex. I'm trying to use a file based config instead of command line, seems like a better idea. I'm on Ubuntu 11. The docs say:

On some packaged installs of MongoDB (for example Ubuntu & Debian), the default file can be found in /etc/mongodb.conf, which is automatically used when starting and stopping MongoDB from the service

I definitely can start mongo with sudo /etc/init.d/mongodb restart but it's starting on the wrong port, 27017:

deploy@ip-xxx-xxx-22-107 ~/app $ sudo lsof -iTCP | grep mongo
mongod     3594   mongodb    5u  IPv4 260392       TCP localhost:27017 (LISTEN)
mongod     3594   mongodb    7u  IPv4 260395       TCP localhost:28017 (LISTEN)

So there's mongo, but not the right port. Whenever I try passing in a config file to the mongodb command I get an error:

 sudo /etc/init.d/mongodb -f /etc/mongodb.conf restart
 * ERROR: wrong args ( -f )

I suspect the /etc/init.d/mongodb command isn't passing on my config request when it's starting mongo. But the config file should be read by default according to the docs. Is something wrong with my Ubuntu install (it's on a PaaS host)? Is there no advantage to using /etc/init.d/mongodb so I should just ignore this? I can get it to read the config file via mongod -f /etc/mongodb.conf but my docs say to use /etc/init.d/mongodb.

jcollum
  • 43,623
  • 55
  • 191
  • 321

1 Answers1

1

Where did you install the mongo package from? If you installed from the default repositories, then you may have a very old version - I just tried on 11.04 (don't have 11.10 handy, sorry) and I got 1.6.4 which is very old (current stable release as of writing this is 2.0.2).

You should remove the version you have, and add the one from the 10gen/MongoDB repositories. The instructions for doing so are here:

http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages

That will give you the latest mongod version and likely resolve your issues, because you seem to be doing things correctly.

Once you have the mongod started, then connect to it and try running this:

use admin
db.runCommand({getCmdLineOpts: 1})

That should give you all the passed and parsed options. There is a sample output shown on the Docs page for the command. It should allow you to see where the mongod is pointing for the config file and what is being parsed from it.

Adam Comerford
  • 21,336
  • 4
  • 65
  • 85
  • `> version() version: 2.0.2 ` – jcollum Feb 25 '12 at 03:45
  • I'm hosted on engine yard if that matters. Installed the 2.02 binaries via this blog post: http://blog.proudcloud.net/2010/09/installing-the-latest-mongodb-package-on-engine-yards-appcloud/ – jcollum Feb 25 '12 at 03:53
  • I've amended the instructions to dig a bit deeper. You might want to take a look at /etc/init/mongod.conf to see how the job is being started (that is the upstart file location by default on Ubuntu). – Adam Comerford Feb 25 '12 at 04:07
  • I started mongo with `sudo /etc/init.d/mongodb restart` and then checked the command line opts. There was no config file in there (should be seeing a .conf in the argv array). – jcollum Feb 25 '12 at 05:00
  • sorry, I missed this comment - what was the outcome here? I think you basically hit on your problem, i.e. that you were not referencing the config file from the init script. This is done if you use the official packages (make sure to use the appropriate options for ubuntu). I just tested this on 11.04, 11.10 and it worked without issues. When you added the 10gen repo did you install mongodb-10gen for example? – Adam Comerford Mar 07 '12 at 23:44
  • Outcome was: not really sure, I think I moved on and forgot about it. – jcollum Mar 22 '12 at 05:14