Usage example at http:https://sibox.isgoodness.com
var pstarter = require('pstarter');
pstarter.startMaster(__dirname + '/config/configs.js').startWorker(function() {
var config = require('./config/configs.js');
var express = require('express');
var bootstrap = require('./app/bootstrap.js');
var app = express.createServer();
bootstrap.setupApp(app, __dirname);
bootstrap.bootstrap(app);
bootstrap.postrun();
app.listen(config.http.port, config.http.ip);
});
var pstarter = require('pstarter');
pstarter.startMaster({}, {exec: './worker.js'});
var pstarter = require('pstarter');
pstarter.startWorker(function() {
console.log('Hello world!');
});
confFile
- configuration file or object. Only PID_FILE and http.numWorkers are used at the momentmasterSettings
- See http:https://nodejs.org/api/cluster.html#cluster_cluster_setupmaster_settingscallback
- function which will be called when master has forked workers
callback
- will call when worker has attached listener on exit signalcleanupCallback
- will call when worker receives exit signal. It pass a function for terminating process (or you can choose to exit).
You need to create a symbolic link /etc/init.d/pstarter to pstarter/etc/init.d/pstarter and make pstarter executable. You need also specify NODE_BIN, SERVER, PID_FILE, NODEJS and NODE_ENV if your application uses it:
NODE_BIN
folder which contains SERVERSERVER
application/server file to executePID_FILE
should be /var/run/pstarter.pid in production linuxNODEJS
executable nodejsNODE_ENV
for your own application; normally development/production
sudo /etc/init.d/pstarter start
sudo /etc/init.d/pstarter restart
sudo /etc/init.d/pstarter graceful
sudo /etc/init.d/pstarter force-restart
sudo /etc/init.d/pstarter stop