4

I've always been testing replicasets by starting multiple mongod processes on the same server (because using multiple serves is more expensive, and I'm merely testing at this point).

However, since I've updated mongo to version v2.0.5 I'm getting the following when I try to start mongod again (on another port, with another database folder, etc.):

mongod already running

Why is this so? Is there a flag to skip this check?

Update: for some reason this only happens when I run mongod like so:

sudo start-stop-daemon --start -c mainuser --exec /usr/local/bin/mongod -- --journal --nohttpinterface --dbpath /home/mainuser/data/db-secondary --logpath /home/mainuser/data/logs/mongodb-secondary.log --logappend --replSet appname --port 30001

It does not happen when I run it like so:

sudo /usr/local/bin/mongod --journal --nohttpinterface --dbpath /home/mainuser/data/db-secondary --logpath /home/mainuser/data/logs/mongodb-secondary.log --logappend --replSet appname --port 30001

Unfortunately I have to use the start-stop-daemon for use in my upstart script on Ubuntu 10.04 LTS. Why would it cause this issue?

After reading the manpage for start-stop-daemon it becomes clear that it is purposely not trying to start the process again because it recognizes it as being the same "service". However, I'm only using start-stop-daemon so that I can run as a different user with Upstart. Is it possible to bypass the check, or run as a non-sudo user in upstart in a different way?

Tom
  • 8,536
  • 31
  • 133
  • 232

3 Answers3

1

Possible solution: You need to use start-stop-daemon's key --name to give diffeent names to different processes. For example for node.js:

start-stop-daemon --name node-charts --start --exec /usr/bin/node -- someapp.js

and

start-stop-daemon --name node-web --start --exec /usr/bin/node -- someotherapp.js

without name it will not start because of it has same /usr/bin/node process name.

Michael Plakhov
  • 2,292
  • 2
  • 19
  • 21
0

This turned out to be a feature of start-stop-daemon, which I used with upstart to run as another user.

By not using start-stop-daemon, this issue was resolved. Inside my upstart script, I now run as mainuser using sudo:

sudo -u mainuser /usr/local/bin/mongod --journal --nohttpinterface --dbpath /home/mainuser/data/db-secondary --logpath /home/mainuser/data/logs/mongodb-secondary.log --logappend --replSet appname --port 30001
Tom
  • 8,536
  • 31
  • 133
  • 232
-1

This is because a pid file already exists for the running mongod.

Just use a different pid with start-stop-daemon. For example,

sudo start-stop-daemon --start --pid=/var/run/mongodb2.pid --chuid mongodb --exec  /usr/bin/mongod -- --config /etc/mongodb2.conf

So it won't complain about "/usr/bin/mongod already running"

Anuj Gupta
  • 10,056
  • 3
  • 28
  • 32
  • Hmm.. I had the same problem as the op, and there was no mongodb.pid file in /var/run.. I did however have another mongodb running (from a command line). When I stopped that one, I was able to use `start-stop-daemon` (which is used by `sudo start mongodb`). – drevicko Jul 30 '13 at 09:43
  • With my apt-installed mongodb (1:2.0.6-1ubuntu4) the init script does NOT have the `--pid` option, but DOES have `--exec /usr/bin/mongod` - that means if the `mongod` executable is running anywhere on the system, the init script won't start it.. – drevicko Jul 30 '13 at 10:38
  • The parameter is `--pidfile` – geronime Nov 21 '14 at 15:34