28

I am new to Mongodb. When I run the following command:

sudo service mongodb start

It shows me "mongodb start/running, process 3566". But when I try to stop by giving the below command:

sudo service mongodb stop

It shows stop: Unknown instance:. Do anybody have any idea how to slove this issue.

And if I give sudo service mongodb restart, I'm getting the below message:

stop: Unknown instance: 
mongodb start/running, process 3644

PS: If I'm using just mongod, I could start the server and could connect the mongo shell by giving mongo.

Please suggest me how to fix the issue and how to connect mongo shell after giving service mongodb start. Thanks in advance.

senthil
  • 1,307
  • 1
  • 11
  • 23
  • Looks like this has been answered here http://stackoverflow.com/questions/10072563/cannot-restart-mongodb-on-ubuntu-11-04 – geakie Nov 09 '12 at 08:09
  • Thanks. But I don't find the log file in log directory /var/log/mongodb/. – senthil Nov 09 '12 at 08:37

5 Answers5

16

I just ran into this. Chances are the issue is in your conf file (obviously, since you reinstalled the seeded)

In the mongodb.conf do not set fork = true if calling it as a service. This will prevent the service call from being able to access it with service mongodb.conf status/stop/restart.

Removing a fork=True line, however, will alleviate the issue.

See comments; use the other solution even though this one is accepted.

GoingTharn
  • 1,123
  • 1
  • 11
  • 19
12

The reason you get the Unknown instance error is because upstart is tracking the wrong PID for the instance of forked mongod process. But the proper solution to this is not running the process in foreground by removing fork=true line from the config like @GoingTharn suggesting, but rather helping upstart to capture the right PID of the forked process by adding

expect daemon

to the /etc/init/mongodb.conf

Alex P.
  • 30,437
  • 17
  • 118
  • 169
  • Thank you so much! worked like a charm on ubuntu 12.04: – user45949 Nov 25 '14 at 15:37
  • 3
    Please, can you make more detail ? maybe copy correct the mongodb.conf file because i dont exp with mongo and cannot understand expect deamon :( – Rueta Feb 16 '15 at 04:33
  • 2
    Why is disabling fork not a proper solution? The [mongodb documentation](http://docs.mongodb.org/manual/reference/program/mongod/#cmdoption--fork) states that you should run mongodb as a daemon "either by using --fork or by using a controlling process that handles the daemonization process (e.g. as with upstart and systemd)" – jonatan May 21 '15 at 10:51
2

I faced exactly the same problem and did the followings:

  • Removed the file mongod.lock (in my case this file was located at /var/lib/mongodb/)
  • Used the following command from my mongo client

mongo --repair

And that fixed the issue. It may be noted that I had a system crash prior to this problem appeared. Therefore, what I believe, the problem was caused due to the unclean shutdown of the server demon.

If you are unsure of the reason, you may wish to have a look at the log file (in my case I found it under /var/log/mongodb/). That might give you some useful hints.

Thanks.

Tanvir
  • 542
  • 7
  • 16
  • 1
    Error parsing command line: unknown option repair try 'mongo --help' for more information – mvladk Jul 06 '15 at 15:45
2

I faced it as you had.Maybe it is because my computer crash unexpectedly.I use the command: sudo top(ubuntu), and I found mongo running.I killed it and start mongo.Every thing turns right.

wendy
  • 29
  • 1
-2

I fixed it by myself. Below is what I did:

 apt-get install mongodb

And overwrote .conf file. After that everything works fine. I hope this would help someone.

senthil
  • 1,307
  • 1
  • 11
  • 23