title: Is mongodb running?
body: <p>I have installed Mongodb and the PHP drivers on my Unix server.</p>
  <p>My question is how can I tell if Mongodb is running? Is there a simple command line query to check status? If I start it once from the shell will it keep running if I exit the shell (this doesn't seem to be the case). How can I make the Mongodb connection persistent and auto start on server reboot?</p>
  <p>I can run:</p>
  <pre><code>-bash-3.2$ su  
  Password:  
  [root@xxx]# cd /var/lib  
  [root@xxx]# ./mongodb-linux-i686-1.6.5/bin/mongod  
  ./mongodb-linux-i686-1.6.5/bin/mongod --help for help and startup options  
  Wed Feb 23 08:06:54 MongoDB starting : pid=7271 port=27017 dbpath=/data/db/ 32-bit  
  
  ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data  
  **       see http://blog.mongodb.org/post/137788967/32-bit-limitations  
  
  ** WARNING: You are running in OpenVZ. This is known to be broken!!!  
  
  Wed Feb 23 08:06:54 db version v1.6.5, pdfile version 4.5  
  Wed Feb 23 08:06:54 git version: 0eb017e9b2828155a67c5612183337b89e12e291  
  Wed Feb 23 08:06:54 sys info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri  
  Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37  
  Wed Feb 23 08:06:54 [initandlisten] waiting for connections on port 27017  
  Wed Feb 23 08:06:54 [websvr] web admin interface listening on port 28017  
  </code></pre>
  <p>If I open a separate shell I can then then connect to mongodb:</p>
  <pre><code>-bash-3.2$ cd /var/lib  
  -bash-3.2$ ./mongodb-linux-i686-1.6.5/bin/mongo  
  MongoDB shell version: 1.6.5  
  connecting to: test  
  &gt; db.foo.find()  
  { &quot;_id&quot; : ObjectId(&quot;4d63d7d3eb95985ab19c8feb&quot;), &quot;a&quot; : 1 }
  </code></pre>
  <p>However if I close the initial shell I can't connect:</p>
  <pre><code>-bash-3.2$ cd /var/lib  
  -bash-3.2$ ./mongodb-linux-i686-1.6.5/bin/mongo  
  MongoDB shell version: 1.6.5  
  connecting to: test  
  Wed Feb 23 08:25:10 Error: couldn't connect to server 127.0.0.1 (anon):1154  
  exception: connect failed
  </code></pre>