Reputation: 1725
When using forever to run a node.js program as a daemon i.e.
forever start myNodeTask
If the daemon (myNodeTask
) decides it needs to exit, what is the correct way to do so?
If I just call process.exit()
the program does terminate but it doesn't delete the forever log file, which leads me to believe that I need the program to exit in a more forever-friendly manner.
The node tasks I'm running are plain tcp servers that stream data to connected clients, not web servers.
Upvotes: 3
Views: 1795
Reputation: 7862
The forever
module always keeps the log files, even after a process has finished. There is no forever-friendly manner to delete those files.
But, you could use the forever-monitor
module, which allow you to programatically use forever
(from the docs):
var forever = require('forever-monitor'),
fs = require('fs');
var child = new (forever.Monitor)('your-filename.js', {
max: 3,
silent: true,
options: []
});
child.on('exit', function () {
console.log('your-filename.js has exited after 3 restarts');
// here you can delete your log file
fs.unlink('path_to_your_log_file', function (err) {
// do something amazing
});
});
child.start();
Upvotes: 1