Blaszard
Blaszard

Reputation: 31955

MongoDB running without executing daemon

I installed MondoDB on my Ubuntu 13.04 and tried to run its daemon by typing in either mongod or sudo mongod, but I encountered the following message:

mongod --help for help and startup options
Thu Jun 27 05:11:02 [initandlisten] MongoDB starting : pid=11685 port=27017 dbpath=/data/db/ 64-bit host=myhost
Thu Jun 27 05:11:02 [initandlisten] db version v2.2.4, pdfile version 4.5
Thu Jun 27 05:11:02 [initandlisten] git version: nogitversion
Thu Jun 27 05:11:02 [initandlisten] build info: Linux batsu 3.2.0-37-generic #58-Ubuntu SMP Thu Jan 24 15:28:10 UTC 2013 x86_64 BOOST_LIB_VERSION=1_49
Thu Jun 27 05:11:02 [initandlisten] options: {}
Thu Jun 27 05:11:02 [initandlisten] journal dir=/data/db/journal
Thu Jun 27 05:11:02 [initandlisten] recover : no journal files present, no recovery needed
Thu Jun 27 05:11:02 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Thu Jun 27 05:11:02 [websvr] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:28017
Thu Jun 27 05:11:02 [websvr] ERROR:   addr already in use
Thu Jun 27 05:11:02 [initandlisten] ERROR:   addr already in use
Thu Jun 27 05:11:02 [initandlisten] now exiting
Thu Jun 27 05:11:02 dbexit: 
Thu Jun 27 05:11:02 [initandlisten] shutdown: going to close listening sockets...
Thu Jun 27 05:11:02 [initandlisten] shutdown: going to flush diaglog...
Thu Jun 27 05:11:02 [initandlisten] shutdown: going to close sockets...
Thu Jun 27 05:11:02 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jun 27 05:11:02 [initandlisten] shutdown: lock for final commit...
Thu Jun 27 05:11:02 [initandlisten] shutdown: final commit...
Thu Jun 27 05:11:02 [initandlisten] shutdown: closing all files...
Thu Jun 27 05:11:02 [initandlisten] closeAllFiles() finished
Thu Jun 27 05:11:02 [initandlisten] journalCleanup...
Thu Jun 27 05:11:02 [initandlisten] removeJournalFiles
Thu Jun 27 05:11:02 [initandlisten] shutdown: removing fs lock...
Thu Jun 27 05:11:02 dbexit: really exiting now

However, when I tried to run MongoDB by typing mongo even without running its daemon, it seems that I can use MongoDB successfully. I don't start any daemon and also I have only one window in my terminal, so it would be impossible to run both daemon and main mongo program at the same time...

So the question is, why I can use MongoDB without starting any daemon process? When I use MongoDB on OS X, I always have to run daemon before using MongoDB. For your information I installed Ubuntu 13.04 via Parallels 8 on my OS X 10.8 and installed MongoDB by going with the same route as an official document explains.

Or since I use MongoDB on my OS X at port 27017, I don't have to run daemon on Virtual Ubuntu? (though I don't run daemon on OS X right now...)

Upvotes: 3

Views: 6463

Answers (3)

Kévin Berthommier
Kévin Berthommier

Reputation: 1572

Start mongod Processes

By default, MongoDB stores data in the /data/db directory. On Windows, MongoDB stores data in C:\data\db. On all platforms, MongoDB listens for connections from clients on port 27017.

To start MongoDB using all defaults, issue the following command at the system shell:

mongod

Stop mongod Processes

In a clean shutdown a mongod completes all pending operations, flushes all data to data files, and closes all data files. Other shutdowns are unclean and can compromise the validity of the data files.

To ensure a clean shutdown, always shutdown mongod instances using one of the following methods:

Use shutdownServer()

Shut down the mongod from the mongo shell using the db.shutdownServer() method as follows:

use admin
db.shutdownServer()

Calling the same method from a init script accomplishes the same result.

For systems with authorization enabled, users may only issue db.shutdownServer() when authenticated to the admin database or via the localhost interface on systems without authentication enabled.

Use --shutdown

From the Linux command line, shut down the mongod using the --shutdown option in the following command:

mongod --shutdown

Upvotes: 0

nandop
nandop

Reputation: 809

Mongod service is running, try to stop it and init mongod with sudo command

sudo service mongodb stop
sudo mongod

Upvotes: 0

AMADANON Inc.
AMADANON Inc.

Reputation: 5919

When you installed mongo, it should already have run the server for you.

This is confirmed by both the fact that it says "addr already in use" (which means something is running on the mongod port) and the fact that you can use it successfully.

You can also test this by running ps wuax | grep mongo and looking for mongod in the resulting list - this list all the processes running on your computer, and then removes from this list anything that doesn't mention mongo. You may also see a line which has "grep" in it - this is the command you are currently running, which you can ignore.

When I run this on my computer, it shows:

mongodb  22394  9.1  1.0 109244 33592 ?        Dsl  08:29   0:01 /usr/bin/mongod --config /etc/mongodb.conf
1001     22423  0.0  0.0   9436   904 pts/3    S+   08:29   0:00 grep --color=auto mongo

Upvotes: 9

Related Questions