Arlolra has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/98004


Change subject: Register a pidfile for api/server.js
......................................................................

Register a pidfile for api/server.js

Bug: 57598
Change-Id: Ia2768d47854d7417f012c2c72ed015939bc2e742
---
M js/api/server.js
1 file changed, 55 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid 
refs/changes/04/98004/1

diff --git a/js/api/server.js b/js/api/server.js
index c892ba5..24d0bb1 100755
--- a/js/api/server.js
+++ b/js/api/server.js
@@ -7,14 +7,59 @@
 var cluster = require('cluster');
 
 if (cluster.isMaster) {
-       // Start a few more workers than there are cpus visible to the OS, so 
that we
-       // get some degree of parallelism even on single-core systems. A single
-       // long-running request would otherwise hold up all concurrent short 
requests.
-       var numCPUs = require('os').cpus().length + 3;
-       console.log('master(' + process.pid + ') initializing ' +
-                               numCPUs + ' workers');
+
+       // process arguments
+       var opts = require( "optimist" )
+               .usage( "Usage: $0 [-h|-v] [--param[=val]]" )
+               .default({
+
+                       // Start a few more workers than there are cpus visible 
to the OS, 
+                       // so that we get some degree of parallelism even on 
single-core
+                       // systems. A single long-running request would 
otherwise hold up
+                       // all concurrent short requests.
+                       c: require( "os" ).cpus().length + 3,
+
+                       // path to write pidfile
+                       p: "",
+
+                       v: false,
+                       h: false
+
+               })
+               .boolean( [ "h", "v" ] )
+               .alias( "h", "help" )
+               .alias( "v", "version" )
+               .alias( "c", "children" )
+               .alias( "p", "pidfile" );
+
+       var argv = opts.argv,
+               fs = require( "fs" ),
+               path = require( "path" ),
+               meta = require( path.join( __dirname, "../package.json" ) );
+
+       // help
+       if ( argv.h ) {
+               opts.showHelp();
+               process.exit( 0 );
+       }
+
+       // version
+       if ( argv.v ) {
+               console.log( meta.name + " " + meta.version );
+               process.exit( 0 );
+       }
+
+       // pidfile
+       var pidfile;
+       if ( argv.p.length ) {
+               pidfile = argv.p;
+               fs.writeFileSync( pidfile, process.pid );
+       }
+
        // Fork workers.
-       for (var i = 0; i < numCPUs; i++) {
+       console.log('master(' + process.pid + ') initializing ' +
+                               argv.c + ' workers');
+       for (var i = 0; i < argv.c; i++) {
                cluster.fork();
        }
 
@@ -36,6 +81,9 @@
                });
                console.log('Done killing workers');
                console.log('Exiting master');
+               if ( pidfile ) {
+                       fs.unlinkSync( pidfile );
+               }
                process.exit(0);
        };
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia2768d47854d7417f012c2c72ed015939bc2e742
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>

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

Reply via email to