Node-Grace
Node-Grace copied to clipboard
Not working with daemon module
Shutdown function is not getting called if , it is used with daemon module (https://github.com/indexzero/daemon.node). Sample code
var grace = require("grace");
var app = grace.create();
app.on("error", function (error) {
//Unhandled and redirected errors
console.error(error);
});
app.on("start", function () {
console.log("starting the app");
setTimeout(function () {
}, 50000);
});
app.on("shutdown", function (cb) {
//This code is not gettting called.
//Clean up tasks
console.log("shutting down");
//Comment this line and the timeout will do its job
cb();
});
app.on("exit", function (code) {
console.log("bye (" + code + ")");
});
app.timeout(1000, function (cb) {
//The timeout is used if the shutdown task takes more time than expected
console.error("timed out, forcing shutdown");
cb();
});
var fs = require('fs-ext');
var fd = fs.openSync("/tmp/vivek.log", 'a');
require('daemon')({
stdout: fd,
stderr: fd
}
);
app.start();
Thanks for reporting. Just a comment, use Linux services instead of the daemon module because if you use an ssh connection and start a node process (even with daemon, nohup, started as a background process or simiilar programs) the node process will be killed. With linux services this problem disappears and you can also redirect file descriptors and start the node process when linux starts. Tested on Ubuntu Server.
Hi gagle, I just tested "node process -even with daemon, nohup". For me nohup , daemon both work fine. Closing ssh connection don't terminate the application.
This wasn't a command. Let me rewrite the sentence :)