Mongo Daemon Doesn't Run by Service Mongod Start

Mongo daemon doesn't run by service mongod start

Docker containers typically does not have a full init system and interaction with upstart will not work inside a docker container. (In theory it is possible, but it defeats the purposes of having light weight stack)

What this implies is that you start a docker container, it would run a single command "/usr/bin/mongod"

Example of running mongodb inside a docker container:
https://docs.docker.com/samples/library/mongo/

Also since you are running installation commands using an interactive docker container, your shell interpreter is the single command as far as docker is considered. Once in interactive session, you can run mongod in background (As you did) and start mongo client session.

Another way would be to run these instructions as part of Dockerfile. You can refer to mongodb example.

You might also want to consider some of the official mongo db images already published in docker hub:

https://registry.hub.docker.com/_/mongo/

mongodb service is not starting up

Fixed!

The reason was the dbpath variable in /etc/mongodb.conf.
Previously, I was using mongodb 1.8, where the default value for dbpath was /data/db.
The upstart job mongodb(which comes with mongodb-10gen package) invokes the mongod with --config /etc/mongodb.conf option.

As a solution, I only had to change the owner of the /data/db directory recursively.

Can't start mongodb service

Check mongodb logs. In my case mongodb could not find directory from mongod.cfg

Mongodb service won't start

After running the repair I was able to start the mongod proccessor but as root, which meant that service mongod start would not work. To repair this issue, I needed to make sure that all the files inside the database folder were owned and grouped to mongod. I did this by the following:

  1. Check the file permissions inside your database folder

    1. note you need to be in your dbpath folder mine was
      /var/lib/mongo I went to cd /var/lib
    2. I ran ls -l mongo
  2. This showed me that databases were owned by root, which is wrong. I ran the following to fix this: chown -R mongod:mongod mongo. This changed the owner and group of every file in the folder to mongod. (If using the mongodb package, chown -R mongodb:mongodb mongodb)

I hope this helps someone else in the future.

How can I run MongoDB as a Windows service?

I think if you run it with the --install command line switch, it installs it as a Windows Service.

mongod --install

It might be worth reading this thread first though. There seems to be some problems with relative/absolute paths when the relevant registry key gets written.

MongoDB on Ubuntu won't start as a service, nothing in the log

OK, this all comes down to permissions, but let's take it step by step. When you run sudo mongod it does not load a config file at all, it literally starts with the compiled in defaults - port 27017, database path of /data/db etc. - that is why you got the error about not being able to find that folder. The "Ubuntu default" is only used when you point it at the config file (if you start using the service command, this is done for you behind the scenes).

Next you ran it like this:

sudo mongod -f /etc/mongodb.conf

If there weren't problems before, then there will be now - you have run the process, with your normal config (pointing at your usual dbpath and log) as the root user. That means that there are going to now be a number of files in that normal MongoDB folder with the user:group of root:root.

This will cause errors when you try to start it as a normal service again, because the mongodb user (which the service will attempt to run as) will not have permission to access those root:root files, and most notably, it will probably not be able to write to the log file to give you any information.

Therefore, to run it as a normal service, we need to fix those permissions. First, make sure MongoDB is not currently running as root, then:

cd /var/log/mongodb
sudo chown -R mongodb:mongodb .
cd /var/lib/mongodb
sudo chown -R mongodb:mongodb .

That should fix it up (assuming the user:group is mongodb:mongodb), though it's probably best to verify with an ls -al or similar to be sure. Once this is done you should be able to get the service to start successfully again.

mongo - couldn't connect to server 127.0.0.1:27017

This error is what you would see if the mongo shell was not able to talk to the mongod server.

This could be because the address was wrong (host or IP) or that it was not running. One thing to note is the log trace provided does not cover the "Fri Nov 9 16:44:06" of your mongo timestamp.

Can you:

  1. Provide the command line arguments (if any) used to start your
    mongod process
  2. Provide the log file activity from the mongod startup as well as
    logs during the mongo shell startup attempt?
  3. Confirm that your mongod process is being started on the same
    machine as the mongo shell?


Related Topics



Leave a reply



Submit