diff --git a/coffee/persistence.coffee b/coffee/persistence.coffee index 613d7c2..4ecf17a 100644 --- a/coffee/persistence.coffee +++ b/coffee/persistence.coffee @@ -63,6 +63,9 @@ exports.initPort = ( port ) => exports.eventPollers.setDB @db exports.actionInvokers.setDB @db +exports.selectDatabase = ( id ) => + @db.select id + ### Checks whether the db is connected and passes either an error on failure after ten attempts within five seconds, or nothing on success to the callback(err). diff --git a/coffee/webapi-eca.coffee b/coffee/webapi-eca.coffee index 9adbf36..19dd2fc 100644 --- a/coffee/webapi-eca.coffee +++ b/coffee/webapi-eca.coffee @@ -57,35 +57,48 @@ opt = 'h': alias : 'help', describe: 'Display this' + # `-c`, `--config-path`: Specify a path to a custom configuration file, other than "config/config.json" 'c': alias : 'config-path', describe: 'Specify a path to a custom configuration file, other than "config/config.json"' + # `-w`, `--http-port`: Specify a HTTP port for the web server 'w': alias : 'http-port', describe: 'Specify a HTTP port for the web server' + # `-d`, `--db-port`: Specify a port for the redis DB 'd': alias : 'db-port', describe: 'Specify a port for the redis DB' + +# `-s`, `--db-select`: Specify a database + 's': + alias : 'db-select', + describe: 'Specify a database identifier' + # `-m`, `--log-mode`: Specify a log mode: [development|productive] 'm': alias : 'log-mode', describe: 'Specify a log mode: [development|productive]' + # `-i`, `--log-io-level`: Specify the log level for the I/O. in development expensive origin # lookups are made and added to the log entries 'i': alias : 'log-io-level', describe: 'Specify the log level for the I/O' + # `-f`, `--log-file-level`: Specify the log level for the log file 'f': alias : 'log-file-level', describe: 'Specify the log level for the log file' + # `-p`, `--log-file-path`: Specify the path to the log file within the "logs" folder 'p': alias : 'log-file-path', describe: 'Specify the path to the log file within the "logs" folder' + # `-n`, `--nolog`: Set this true if no output shall be generated 'n': alias : 'nolog', @@ -133,6 +146,7 @@ init = => # > Fetch the `http-port` argument args[ 'http-port' ] = parseInt argv.w || conf.getHttpPort() args[ 'db-port' ] = parseInt argv.d || conf.getDbPort() + args[ 'db-select' ] = parseInt argv.s || conf.fetchProp 'db-select' #FIXME this has to come from user input for security reasons: args[ 'keygen' ] = conf.getKeygenPassphrase() @@ -146,6 +160,7 @@ init = => #TODO eventually we shouldn't let each module load its own persistence #module, but hand this one through them via the args... db.isConnected ( err ) => + db.selectDatabase parseInt( args[ 'db-select' ] ) || 0 if err @log.error 'RS | No DB connection, shutting down system!' shutDown() diff --git a/config/system.json b/config/system.json index fc5282f..b8ab5e4 100644 --- a/config/system.json +++ b/config/system.json @@ -1,6 +1,7 @@ { "http-port": 8125, "db-port": 6379, + "db-select": 0, "log": { "nolog": "false", "mode": "development", diff --git a/js/persistence.js b/js/persistence.js index 2ff4e38..a90d0d3 100644 --- a/js/persistence.js +++ b/js/persistence.js @@ -79,6 +79,12 @@ Persistence }; })(this); + exports.selectDatabase = (function(_this) { + return function(id) { + return _this.db.select(id); + }; + })(this); + /* Checks whether the db is connected and passes either an error on failure after diff --git a/js/webapi-eca.js b/js/webapi-eca.js index 6e1bab2..95d97ce 100644 --- a/js/webapi-eca.js +++ b/js/webapi-eca.js @@ -65,6 +65,10 @@ WebAPI-ECA Engine alias: 'db-port', describe: 'Specify a port for the redis DB' }, + 's': { + alias: 'db-select', + describe: 'Specify a database identifier' + }, 'm': { alias: 'log-mode', describe: 'Specify a log mode: [development|productive]' @@ -147,6 +151,7 @@ WebAPI-ECA Engine }; args['http-port'] = parseInt(argv.w || conf.getHttpPort()); args['db-port'] = parseInt(argv.d || conf.getDbPort()); + args['db-select'] = parseInt(argv.s || conf.fetchProp('db-select')); args['keygen'] = conf.getKeygenPassphrase(); args['webhooks'] = conf.fetchProp('webhooks'); encryption(args); @@ -154,6 +159,7 @@ WebAPI-ECA Engine db(args); return db.isConnected(function(err) { var cliArgs, poller; + db.selectDatabase(parseInt(args['db-select']) || 0); if (err) { _this.log.error('RS | No DB connection, shutting down system!'); return shutDown();