mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-12-19 19:10:40 +00:00
12a45cff1b
Uses nodejs to call phantomjs that renders the tex input using MathJax and returns a json object that includes both the SVG and the MathML representation. The project was forked from https://github.com/agrbin/svgtex. Co-Authored-By: Gabriel Wicke <gwicke@wikimedia.org> Co-Authored-By: Moritz Schubotz <wiki@physikerwelt.de> Change-Id: Ie5f24006c3aacd8f61f48ca275acd63a418d7529
48 lines
1.4 KiB
JavaScript
Executable file
48 lines
1.4 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
/**
|
|
* A very basic cluster-based server runner. Restarts failed workers, but does
|
|
* not much else right now.
|
|
*/
|
|
|
|
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;
|
|
// Fork workers.
|
|
for (var i = 0; i < numCPUs; i++) {
|
|
cluster.fork();
|
|
}
|
|
|
|
cluster.on('exit', function(worker) {
|
|
if (!worker.suicide) {
|
|
var exitCode = worker.process.exitCode;
|
|
console.log('worker', worker.process.pid,
|
|
'died ('+exitCode+'), restarting.');
|
|
cluster.fork();
|
|
}
|
|
});
|
|
|
|
process.on('SIGTERM', function() {
|
|
console.log('master shutting down, killing workers');
|
|
var workers = cluster.workers;
|
|
Object.keys(workers).forEach(function(id) {
|
|
console.log('Killing worker ' + id);
|
|
workers[id].destroy();
|
|
});
|
|
console.log('Done killing workers, bye');
|
|
process.exit(1);
|
|
} );
|
|
} else {
|
|
var mathoidWorker = require('./mathoid-worker.js');
|
|
process.on('SIGTERM', function() {
|
|
console.log('Worker shutting down');
|
|
process.exit(1);
|
|
});
|
|
// when running on appfog.com the listen port for the app
|
|
// is passed in an environment variable. Most users can ignore this!
|
|
mathoidWorker.listen(process.env.VCAP_APP_PORT || 8010);
|
|
}
|