2

Related question, didn't fix the issue: MongoDB not using /etc/mongodb.conf after I changed dbpath

On Ubuntu 12.04. $ mongod --version = db version v2.4.9

I'd like the mongo service to use /etc/mongodb.conf (I thought it was set to do that out of the box but apparently not).

$ cat /etc/mongodb.conf | grep dbpath
dbpath=/home/xyz/mongodb

$ cat /etc/mongodb.conf | grep logpath
logpath=/home/xyz/mongodb-logs

$ ll /home/xyz| grep mongo
drwxrwxr-x  2 mongodb mongodb  4096 Feb 19 11:58 mongodb/
drwxrwxr-x  2 mongodb mongodb  4096 Feb 19 11:58 mongodb-logs/

(the instructions say it should be mongod user but that doesn't exist, while mongodb does, instructions incorrect?)

But whenever I start mongod it tries to use /data/db:

ERROR: dbpath (/data/db/) does not exist.

I've looked in the init.d script and don't see any options for config path:

$ cat  /etc/init.d/mongodb | grep config
# release without the 'show-config' command (introduced in
    initctl show-config -e "$JOB"|grep -q '^  start on' || DISABLED=1

When I restart the service it appears to immediately stop:

$ sudo service mongodb restart
stop: Unknown instance: 
mongodb start/running, process 2495
$ sudo service mongodb status
mongodb stop/waiting

Is this a bug? It appears to be ignoring the config file. I know I can start it using --dbpath or --config, but shouldn't it be reading the config file if it isn't provided a dbpath? Since the service is failing to start (apparently) where can I find the error that caused it to fail?

Community
  • 1
  • 1
jcollum
  • 43,623
  • 55
  • 191
  • 321
  • @PeteGarafano "but shouldn't it be reading the config file if it isn't provided a dbpath?" like I said -- why is it not reading the config file? It seems weird that any tool would ignore it's one and only config file when not provided with an alternate. – jcollum Feb 19 '14 at 21:31
  • Also, you missed this part: " If you installed from a package [I did, the PPA] and have started MongoDB using your system’s control script [I think this is the same as using the service], you’re already using a configuration file." -- except it's not using the config file. – jcollum Feb 19 '14 at 21:32
  • 1
    Have you tried specifying the config file with --config? – Pete Garafano Feb 19 '14 at 21:39
  • trying running `mkdir -p /data/db; chown mongodb:mongodb -R /data/db` and then running `service mongodb start` – Alexej Magura Feb 19 '14 at 21:42
  • What I'm trying to figure out is if it just defaults to hardcoded values if you don't provide --config. The docs imply that you don't need to use the --config option. – jcollum Feb 19 '14 at 21:42
  • @AlexejMagura that would completely defeat the purpose of changing the dbpath in config. – jcollum Feb 19 '14 at 21:43
  • 1
    @Jcollum, if you want to be sure that mongodb is reading from the config file even when you start it with `service mongodb start`, then change the service file so that mongodb is started with `--config ` – Alexej Magura Feb 19 '14 at 21:44
  • I've just installed from the repos myself for the first time ever so Ill try this out, it should be running on your system with the config arg if you do `ps aux | grep mongod` – Sammaye Feb 19 '14 at 21:47
  • As can be seen when I do it: `mongodb 23017 0.3 3.5 520260 59656 ? Ssl Feb16 14:26 /usr/bin/mongo --config /etc/mongodb.conf` – Sammaye Feb 19 '14 at 21:48
  • "then change the service file so that mongodb is started with" -- so the docs are wrong? – jcollum Feb 19 '14 at 21:49
  • They shouldn't be, your mongod should be running with /etc/mongodb.conf, I just showed you my run line from installing from repo – Sammaye Feb 19 '14 at 21:50
  • Sorry I actually supplied the wrong output, here is the real one: `mongodb 23017 0.3 4.4 520260 76064 ? Ssl Feb16 14:27 /usr/bin/mongod --config /etc/mongodb.conf` I supplied the `mongo` shell program – Sammaye Feb 19 '14 at 21:54
  • Are you starting that via the service? – jcollum Feb 19 '14 at 21:58
  • Yep that is straight from the 10-gen repo as described in the docs – Sammaye Feb 19 '14 at 22:01
  • Same thing I'm doing, but it's not working. This is a fresh Ubuntu VM and a fresh mongo install. – jcollum Feb 19 '14 at 22:01
  • If I use the service? Nothing. It doesn't start. – jcollum Feb 19 '14 at 22:04
  • Ok check in /var/log/mongodb.log and see what config it says it is using there when it goes to start up – Sammaye Feb 19 '14 at 22:07
  • i.e. mine says: `Sun Feb 16 18:17:57.159 [initandlisten] options: { config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", logappend: "true", logpath: "/var/log/mongodb/mongodb.log" }` – Sammaye Feb 19 '14 at 22:07
  • I think this is OT on SO it's administration, so it should go to dba.SE, right? – mnemosyn Feb 20 '14 at 10:48
  • @mnemosyn could be yes, could be no; there's a lot of these kinds of questions on SO. – jcollum Feb 20 '14 at 19:00

1 Answers1

2

I had a similar problem (on v3.2) which turned out to be due to an error in my /etc/mongod.conf. I had the following:

replication:
  replSet: rs0

which should have been:

replication:
  replSetName: rs0

Starting mongod via sudo service mongod start failed silently with nothing in the logs. Fixing the config allowed mongod to start.

This was actually on RHEL, and I verified that the init script was passing --config /etc/mongod.conf. I assume it's the same on Ubuntu.

Justin Lewis
  • 1,261
  • 1
  • 15
  • 33