1

I'd like to run mongoDB as a service. The instance shall be configured as a single-node replicaset to be able to connect a elasticSearch instance to it with a the connector.

So I extended the mongod.conf:

...
replication:
  replSetName: "singleNodeRepl"
...

I tried different ways to start now the mongod, but nothing works.

When I try to start the service by $ service mongod start, following error is thrown:

start: Rejected send message, 1 matched rules; type="method_call", sender=":1.106" (uid=1225 pid=26018 comm="start mongod ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")

When I execute this command as sudo (whats not best-practise, right?), its "running" and following message is shown:

mongod start/running, process 26034

But process 26034 doesn't exist and ps aux | grep mongo also shows nothing?!

Next try: Run it as a normal application

mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl

Here following exception is shown:

2016-04-08T14:31:35.192+0200 I STORAGE  [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /var/lib/mongodb/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-04-08T14:31:35.192+0200 I CONTROL  [initandlisten] dbexit:  rc: 100

Everything is fine when I run ~$ sudo mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl, but thats not my target: Its not running as a service and its running as root.

The mongod-logfile often keeps untouched. But the last lines are curious:

2016-04-08T14:24:56.242+0200 E NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-04-08T14:24:56.242+0200 I -        [initandlisten] Fatal Assertion 28578
2016-04-08T14:24:56.242+0200 I -        [initandlisten]
***aborting after fassert() failure

A mongodb-27017.sock existed, but deleting (what was suggested anywhere) didn't help.

Based on the erros above if tried serveral solutions, but nothing helps.

I think it's a very simple mistake...but which one?

[edit:] I discovered, that I perhaps should have specified the config-location. So the (working but bad) command looks like:

$ sudo mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl --config /etc/mongod.conf

This brings following error:

warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default

Thats an old thing, which was the solution for this problem and suddenly doesn't work anymore!?

Community
  • 1
  • 1
MUmla
  • 445
  • 1
  • 8
  • 26
  • In the logs, I noticed a lock file couldn't be created or opened. Could it be a user permission issue? What's the permissions for the ``/var/lib/mongodb/``? – notorious.no Apr 08 '16 at 12:56
  • `rwxr-xr-x 4 mongodb mongodb 4096 Apr 8 14:31 mongodb` – MUmla Apr 08 '16 at 12:58
  • Did you try deleting both the .sock and .lock file? – airudah Apr 08 '16 at 13:37
  • I extended my question. – MUmla Apr 08 '16 at 14:50
  • 1
    Might just be a typo but I noticed you have "singleNodeRepl" in your conf file and "SingleNodeRepl" on the command line in your edit. Perhaps try starting again with just the config param. So `mongod --config /etc/mongod.conf` – airudah Apr 08 '16 at 15:00
  • Ha, thats not just a typo in my question! Well observed, great, thanks! But that doesn't solve my service-problem :/ – MUmla Apr 08 '16 at 15:06

2 Answers2

0

I've had issues stopping and starting mongod as a service. Turns out there was an issue with the upsart script. I found this discussion which seemed to fix it.

The suggested solution was pretty much: (copy pasting now)

vim /etc/init.d/mongod

look for stop() function (and start() function for good measure) and remove quotes around $PIDFILE in the following line.

killproc -p $PIDFILE -d 300 /usr/bin/mongod

airudah
  • 1,169
  • 12
  • 19
  • interesting. mongod is missing in /etc/init.d/ on my machine?! But I've done everything mentioned here (https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu) during installation?! Of course! It has something to do with the switch from init.d to SysV on ubuntu! Investigation in process... – MUmla Apr 08 '16 at 15:11
  • Could be this problem here: http://stackoverflow.com/questions/10733201/mongodb-is-not-starting-in-ubuntu – MUmla Apr 08 '16 at 15:24
  • That would be strange if you followed the ubuntu instructions and didn't get a mongod file. Perhaps create one as suggested. – airudah Apr 08 '16 at 17:04
0

Do this:

sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start

Let me know if this doesn't work!

Abhilash Reddy
  • 1,499
  • 1
  • 12
  • 24
  • I did this already in a similar way as mentioned in the question. When I do this (with correct dbpath), I get this error: `exception in initAndListen: 98 Unable to create/open lock file: /var/lib/mongodb/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating` But the mongod.lock doesn't exist (anymore). Crazy. – MUmla Apr 12 '16 at 11:13