Is mongodb running?
Solution 1:
check with either:
ps -edaf | grep mongo | grep -v grep # "ps" flags may differ on your OS
or
/etc/init.d/mongodb status # for MongoDB version < 2.6
/etc/init.d/mongod status # for MongoDB version >= 2.6
or
service mongodb status # for MongoDB version < 2.6
service mongod status # for MongoDB version >= 2.6
to see if mongod is running (you need to be root to do this, or prefix everything with sudo
). Please note that the 'grep' command will always also show up as a separate process.
Check the log file /var/log/mongo/mongo.log
to see if there are any problems reported.
Solution 2:
I find:
ps -ax | grep mongo
To be a lot more consistent. The value returned can be used to detect how many instances of mongod there are running
Solution 3:
For quickly checking if mongodb is running, this quick nc trick will let you know.
nc -zvv localhost 27017
The above command assumes that you are running it on the default port on localhost.
For auto-starting it, you might want to look at this thread.
Solution 4:
this should work fine...
pgrep mongod