Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Forever - living dead processors
var http = require('http');
http.createServer(function (req, res) {
res.end("emitter.js is running");
}).listen(1337, "127.0.0.1");
console.log('output form emitter.js: emitter.js is running');
Andreas-Madsens-MacBook-Pro:~ Andreas$ cd Sites/WebNodes/interface/
Andreas-Madsens-MacBook-Pro:interface Andreas$ node test.js
Output forever list:
Number of open processors: 0
null
start emitter.js
emitter.js is started
Output forever list:
Number of open processors: 1
[0] node /Users/Andreas/Sites/WebNodes/interface/emitter.js [4483, 4482] /Users/Andreas/Sites/WebNodes/interface/log/S9H7.log 0:0:0:0.38
stop all processors
Andreas-Madsens-MacBook-Pro:interface Andreas$ node test.js
Output forever list:
Number of open processors: 1
[0] node /Users/Andreas/Sites/WebNodes/interface/emitter.js [4483, 4482] /Users/Andreas/Sites/WebNodes/interface/log/S9H7.log 0:0:0:15.741
start emitter.js
emitter.js is started
Output forever list:
Number of open processors: 2
[0] node /Users/Andreas/Sites/WebNodes/interface/emitter.js [4491, 4490] /Users/Andreas/Sites/WebNodes/interface/log/Dd3D.log 0:0:0:0.34
[1] node /Users/Andreas/Sites/WebNodes/interface/emitter.js [4483, 4482] /Users/Andreas/Sites/WebNodes/interface/log/S9H7.log 0:0:0:15.777
stop all processors
Andreas-Madsens-MacBook-Pro:interface Andreas$
/*jslint white: true, devel: true, debug: true, onevar: true,
node: true, undef: true, nomen: true, regexp: false,
plusplus: false, bitwise: true, unparam: false, es5: true,
newcap: true, on: true, strict: true */
(function (global, undefined) {
"use strict";
//!! I still need to figure out why node search in /usr/local/lib/node ??
require.paths = [ '/Users/Andreas/.node_modules', '/usr/local/lib/node_modules' ];
//get the forever module
var forever = require("forever"),
rootPath = process.cwd(),
emitter = rootPath + "/emitter.js",
outputList = function () {
console.log("Output forever list:");
var list = (forever.list(false) || []),
open = 0;
for (var i=0,il=list.length; i<il; i++) {
if (list[i].dead !== true) {
open++;
}
}
console.log("Number of open processors: ", open);
console.log(forever.list(true));
};
//Load data
forever.load({
root : rootPath + "/log/",
pidPath : rootPath + "/.forever/"
});
//Output list
outputList();
//Start
console.log("start emitter.js");
forever.start(emitter, {
forever: false,
"outFile" : rootPath + "/log/emitter_output.log",
"errFile" : rootPath + "/log/emitter_error.log"
}).on("start", function () {
//Output list
console.log("emitter.js is started");
outputList();
console.log("");
console.log("");
console.log("stop all processors");
forever.stopAll(false).on("stopAll", function () {
console.log("All processors is stop");
outputList();
console.log("");
console.log(forever.list(false));
});
})
})(global);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.