diff --git a/js/server/modules/org/arangodb/cluster/dispatcher.js b/js/server/modules/org/arangodb/cluster/dispatcher.js index 25749d13ec..ea02007957 100644 --- a/js/server/modules/org/arangodb/cluster/dispatcher.js +++ b/js/server/modules/org/arangodb/cluster/dispatcher.js @@ -33,14 +33,58 @@ // ----------------------------------------------------------------------------- var download = require("internal").download; +var executeExternal = require("internal").executeExternal; +var fs = require("fs"); +var wait = require("internal").wait; var print = require("internal").print; var actions = {}; +function getAddrPort (endpoint) { + var pos = endpoint.indexOf("://"); + if (pos !== -1) { + return endpoint.substr(pos+3); + } + return endpoint; +} + +function getAddr (endpoint) { + var addrPort = getAddrPort(endpoint); + var pos = addrPort.indexOf(":"); + if (pos !== -1) { + return addrPort.substr(0,pos); + } + return addrPort; +} + actions.startAgent = function (dispatchers, cmd) { - print("Starting an agent..."); - return {"error":false}; + var agentDataDir = fs.join(cmd.dataPath, + "agent"+cmd.agencyPrefix+cmd.extPort) + if (fs.exists(agentDataDir)) { + fs.removeDirectoryRecursive(agentDataDir,true); + } + // FIXME: could distinguish cases and sometimes only bind to 127.0.0.1??? + var args = ["-data-dir", agentDataDir, + "-name", "agent"+cmd.agencyPrefix+cmd.extPort, + "-addr", "0.0.0.0:"+cmd.extPort, + "-peer-addr", "0.0.0.0:"+cmd.intPort]; + var i; + if (cmd.peers.length > 0) { + args.push("-peers"); + var st = getAddrPort(cmd.peers[0]); + for (i = 1; i < cmd.peers.length; i++) { + st = st + "," + getAddrPort(cmd.peers[i]); + } + args.push(getAddrPort(cmd.peers[0])); + } + print("Starting agent: command: ",cmd.agentPath); + for (i = 0;i < args.length;i++) { + print(args[i]); + } + var pid = executeExternal(cmd.agentPath, args); + wait(3); // Wait a bit, such that the next one will be able to connect + return {"error":false, "pid": pid}; }; actions.sendConfiguration = function (dispatchers, cmd) { diff --git a/js/server/modules/org/arangodb/cluster/kickstarter.js b/js/server/modules/org/arangodb/cluster/kickstarter.js index 46e8dbdf4c..611e49fe10 100644 --- a/js/server/modules/org/arangodb/cluster/kickstarter.js +++ b/js/server/modules/org/arangodb/cluster/kickstarter.js @@ -45,13 +45,25 @@ // .dataPath a file system path to the directory in which // all the data directories of agents or servers // live, this can be relative or even empty, which -// is equivalent to "./", please end with a slash -// if not empty +// is equivalent to "./", it will be made into +// an absolute path by the kickstarter, using +// the current directory when the kickstarter +// runs, use with caution! +// .logPath path where the log files are written, same +// comments as for .dataPath apply // .dispatchers an list of pairs of strings, the first entry // is an ID, the second is an endpoint or "me" // standing for the local `arangod` itself. // this list can be empty in which case // ["me","me"] is automatically added. +// .arangodPath path to the arangod executable on +// all machines in the cluster, will be made +// absolute (if it is not already absolute) +// in the process running the kickstarter +// .agentPath path to the agent executable on +// all machines in the cluster, will be made +// absolute (if it is not already absolute) +// in the process running the kickstarter // some port lists: // for these the following rules apply: // every list overwrites the default list @@ -66,6 +78,7 @@ // .coordinatorPorts a list ports to try to use for coordinators // +fs = require("fs"); dispatch = require("org/arangodb/cluster/dispatcher").dispatch; // Our default configurations: @@ -82,6 +95,8 @@ var KickstarterLocalDefaults = { "Claas", "Clemens", "Chris" ], "dataPath" : "", "logPath" : "", + "arangodPath" : "bin/arangod", + "agentPath" : "bin/etcd", "agentExtPorts" : [4001], "agentIntPorts" : [7001], "DBserverPorts" : [8629], @@ -102,6 +117,8 @@ var KickstarterDistributedDefaults = { "Claas", "Clemens", "Chris" ], "dataPath" : "", "logPath" : "", + "arangodPath" : "bin/arangod", + "agentPath" : "bin/etcd", "agentExtPorts" : [4001], "agentIntPorts" : [7001], "DBserverPorts" : [8629], @@ -240,6 +257,12 @@ function Kickstarter (userConfig) { } this.config = copy(userConfig); fillConfigWithDefaults(this.config, defaultConfig); + this.config.dataPath = fs.normalize(fs.makeAbsolute(this.config.dataPath)); + this.config.logPath = fs.normalize(fs.makeAbsolute(this.config.logPath)); + this.config.arangodPath = fs.normalize(fs.makeAbsolute( + this.config.arangodPath)); + this.config.agentPath = fs.normalize(fs.makeAbsolute( + this.config.agentPath)); this.commands = []; this.makePlan(); } @@ -400,9 +423,13 @@ Kickstarter.prototype.makePlan = function() { var tmp2,j; for (i = 0; i < agents.length; i++) { tmp2 = { "action" : "startAgent", "dispatcher": agents[i].dispatcher, - "ports": { "extPort": agents[i].extPort, - "intPort": agents[i].intPort }, - "peers": [] }; + "extPort": agents[i].extPort, + "intPort": agents[i].intPort, + "peers": [], + "agencyPrefix": config.agencyPrefix, + "dataPath": config.dataPath, + "logPath": config.logPath, + "agentPath": config.agentPath }; for (j = 0; j < i; j++) { var ep = dispatchers[agents[j].dispatcher].endpoint; tmp2.peers.push( exchangePort( ep, agents[j].intPort ) ); @@ -421,6 +448,7 @@ Kickstarter.prototype.makePlan = function() { "name": dispList[i], "dataPath": config.dataPath, "logPath": config.logPath, + "arangodPath": config.arangodPath, "agency": copy(agencyPos) } ); } this.myname = "me"; diff --git a/lib/ApplicationServer/ApplicationServer.h b/lib/ApplicationServer/ApplicationServer.h index 5e745a54e4..cc3105e046 100644 --- a/lib/ApplicationServer/ApplicationServer.h +++ b/lib/ApplicationServer/ApplicationServer.h @@ -330,6 +330,12 @@ namespace triagens { /// @{ //////////////////////////////////////////////////////////////////////////////// +#if 0 +public: +void guck() { + _options.guck(); +} +#endif private: //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/Basics/ProgramOptions.h b/lib/Basics/ProgramOptions.h index f4b86c7a02..e5f3183238 100644 --- a/lib/Basics/ProgramOptions.h +++ b/lib/Basics/ProgramOptions.h @@ -133,6 +133,30 @@ namespace triagens { string lastError (); +#if 0 +void guck () { + vector::iterator i; + map::iterator j; + + cout << "OPTGUCK:" << endl; + for (i = _options.begin(); i != _options.end(); ++i) { + j = _valuesString.find(*i); + if (j == _valuesString.end()) { + cout << "OPT: " << *i << " not in _valuesString" << endl; + } + else if (0 == j->second) { + cout << "OPT: " << *i << " is 0" << endl; + } + else if (0 == *(j->second)) { + cout << "OPT: " << *i << " is *0" << endl; + } + else { + cout << "OPT: " << *i << " with value " << *(j->second) << endl; + } + } +} +#endif + //////////////////////////////////////////////////////////////////////////////// /// @} ////////////////////////////////////////////////////////////////////////////////