jenkins-bot has submitted this change and it was merged.

Change subject: Use `/etc/mw-collection-ocg.js` configuration file if present.
......................................................................


Use `/etc/mw-collection-ocg.js` configuration file if present.

The documentation at the top of `defaults.js` mentions this file, but it
is nowhere loaded by default.  Since the provided upstart file doesn't
specify a `-c` option, we need to look for this override in a different way.

Note that this allows multiple levels of configuration -- the distribution's
default configuration file in `/etc/mw-collection-ocg.js` can specify another
more-local configuration in `/usr/local/etc/` which can then in turn fall
back to a user configuration in `$HOME`, etc.

Change-Id: Ie50b823d7dec510b30f5366c83e371c685576fee
---
M README.md
M defaults.js
M mw-ocg-service.js
3 files changed, 25 insertions(+), 3 deletions(-)

Approvals:
  Cscott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/README.md b/README.md
index e1763f3..827bfe4 100644
--- a/README.md
+++ b/README.md
@@ -8,12 +8,18 @@
 
 ## Installation on Ubuntu
 
-```
+Ensure that you have a redis server installed somewhere.
+
+```sh
+cd <repodir> ; npm install
 ln -s <repodir>/mw-collection-ocg.conf /etc/init
 initctl reload-configuration
 service mw-collection-ocg start
 ```
 
+Create `/etc/mw-collection-ocg.js` to configure the render service.
+See [the default configuration](./defaults.js) for more details.
+
 ## Binary node modules
 The following node binary modules are required:
 * hiredis
diff --git a/defaults.js b/defaults.js
index 31aa9bf..e8d8bae 100644
--- a/defaults.js
+++ b/defaults.js
@@ -6,6 +6,9 @@
  * module.exports = function(config) { config.foo = 'bar'; }
  */
 module.exports = {
+       /** Location of local configuration override(s) (if present) */
+       "config": "/etc/mw-collection-ocg.js",
+
        /** Service management thread, coordinates (re)launching threads and 
initial global setup */
        "coordinator": {
                /** The number of frontend threads to spawn. At the moment we 
don't have good data on how
diff --git a/mw-ocg-service.js b/mw-ocg-service.js
index c93be03..ff978d2 100755
--- a/mw-ocg-service.js
+++ b/mw-ocg-service.js
@@ -34,6 +34,7 @@
 
 var cluster = require( 'cluster' );
 var commander = require( 'commander' );
+var fs = require('fs');
 var path = require( 'path' );
 var StatsD = require( './lib/statsd.js' );
 var os = require( 'os' );
@@ -41,6 +42,18 @@
 
 /* === Configuration Options & File ======================================== */
 var config = require( './defaults.js' );
+// local configuration overrides
+while (config.config) {
+    var config_file = config.config;
+    delete config.config;
+    try {
+       fs.statSync(config_file);
+    } catch (e) {
+       break; // file not present
+    }
+    config = require( config_file )( config ) || config;
+}
+// parse command-line options (with a possible additional config file override)
 commander
        .version( '0.0.1' )
        .option( '-c, --config <path>', 'Path to the local configuration file' )
@@ -52,9 +65,9 @@
                        // If the configuration path given is relative, resolve 
it to be relative
                        // to the current working directory instead of relative 
to the path of this
                        // file.
-                       commander.config = path.resolve( process.cwd, 
commander.config );
+                       commander.config = path.resolve( process.cwd(), 
commander.config );
                }
-               config = require( commander.config )( config );
+               config = require( commander.config )( config ) || config;
        }
 } catch ( err ) {
        console.error( "Could not open configuration file %s! %s", 
commander.config, err );

-- 
To view, visit https://gerrit.wikimedia.org/r/159099
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie50b823d7dec510b30f5366c83e371c685576fee
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Collection/OfflineContentGenerator
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Marcoil <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to