mongod --status or similar available?

14 views
Skip to first unread message

Stephan Fortelny

unread,
Apr 25, 2012, 10:03:38 AM4/25/12
to mongodb-user
hi,

for testing I start mongod via makefile if not already running. my
code is like this:

PID_MONGO := $(shell pidof mongod)

mongodb: $(TMP) $(MONGODB_PATH)
ifeq ('$(PID_MONGO)', '')
echo "Starting mongod ..."
mongod --dbpath $(MONGODB_PATH) &
echo "Waiting $(MONGODB_STARTUP_TIME) seconds for mongod to startup"
sleep $(MONGODB_STARTUP_TIME)
endif

however, the timeout with sleep is because journaling can sometimes
take up to 2min. on the console mongod writes '[initandlisten] waiting
for connections on port NUMBER' when mongod is ready.

thus, something like 'mongod --status' would be really helpful to
avoid the sleep call with the static number. does anything like this
exist? yes I checked the --help switch, but couldn't find anything

More precisely, I want to replace

echo "Waiting $(MONGODB_STARTUP_TIME) seconds for mongod to startup"
sleep $(MONGODB_STARTUP_TIME)

with something like

PID_STATUS := $(shell mongod --status)
while neq(PID_STATUS, 'status'); do \
sleep 5s
PID_STATUS := $(shell mongod --status)
done

or even better with a blocking call like

$(shell mongod --waitForReadyState)
#continue

Dan Crosta

unread,
Apr 25, 2012, 10:49:06 AM4/25/12
to mongodb-user
Unfortunately there's no --status flag.

If you start mongod with the --rest option, you can use the presence
(or not) of the HTTP REST interface to determine whether a mongod is
up and accepting connections or not. The HTTP interface runs on a port
1000 ports higher than the usual mongod port -- so, by default, it
listens on 28017. Like the main mongod port, mongod does not begin
listening on this port if it is still allocating journal files. You
can use something like curl or wget from your startup script to test
whether the interface is litening yet or not.

- Dan


On Apr 25, 10:03 am, Stephan Fortelny <stephanforte...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages