summaryrefslogtreecommitdiff
path: root/shell/servers.js
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-02-17 09:38:03 -0500
committerEliot Horowitz <eliot@10gen.com>2009-02-17 09:38:03 -0500
commit873ab5b6664aef749e827428f47e779da1f9aad8 (patch)
treeeb1ec8a7bda5e1fb3ba2365822e5ea5eba0bbb50 /shell/servers.js
parent566af4dc73e74e2f0b5a566455d82319ec312537 (diff)
downloadmongo-873ab5b6664aef749e827428f47e779da1f9aad8.tar.gz
split out server stuff from mongo.js
Diffstat (limited to 'shell/servers.js')
-rw-r--r--shell/servers.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/shell/servers.js b/shell/servers.js
new file mode 100644
index 00000000000..ae8f5665b2e
--- /dev/null
+++ b/shell/servers.js
@@ -0,0 +1,61 @@
+
+
+_parsePath = function() {
+ var dbpath = "";
+ for( var i = 0; i < arguments.length; ++i )
+ if ( arguments[ i ] == "--dbpath" )
+ dbpath = arguments[ i + 1 ];
+
+ if ( dbpath == "" )
+ throw "No dbpath specified";
+
+ return dbpath;
+}
+
+_parsePort = function() {
+ var port = "";
+ for( var i = 0; i < arguments.length; ++i )
+ if ( arguments[ i ] == "--port" )
+ port = arguments[ i + 1 ];
+
+ if ( port == "" )
+ throw "No port specified";
+ return port;
+}
+
+// Start a mongod instance and return a 'Mongo' object connected to it.
+// This function's arguments are passed as command line arguments to mongod.
+// The specified 'dbpath' is cleared if it exists, created if not.
+startMongod = function() {
+ var dbpath = _parsePath.apply( null, arguments );
+ resetDbpath( dbpath );
+ var fullArgs = Array();
+ fullArgs[ 0 ] = "mongod";
+ for( i = 0; i < arguments.length; ++i )
+ fullArgs[ i + 1 ] = arguments[ i ];
+ return startMongoProgram.apply( null, fullArgs );
+}
+
+// Start a mongo program instance (generally mongod or mongos) and return a
+// 'Mongo' object connected to it. This function's first argument is the
+// program name, and subsequent arguments to this function are passed as
+// command line arguments to the program.
+startMongoProgram = function() {
+ var port = _parsePort.apply( null, arguments );
+
+ _startMongoProgram.apply( null, arguments );
+
+ var m;
+ assert.soon
+ ( function() {
+ try {
+ m = new Mongo( "127.0.0.1:" + port );
+ return true;
+ } catch( e ) {
+ }
+ return false;
+ } );
+
+ return m;
+}
+