debian - What is the best way to watch and signal file changes to a node.js app? -
i periodically rsync code changes production server. have following cluster code creates workers main app.
var cluster = require('cluster'); function startworker() { var worker = cluster.fork(); console.log('cluster: worker %d started', worker.id); } if(cluster.ismaster){ require('os').cpus().foreach(function(){ startworker(); }); // log workers disconnect; if worker disconnects, // should exit, we'll wait exit event spawn // new worker replace cluster.on('disconnect', function(worker){ console.log('cluster: worker %d disconnected cluster.', worker.id); }); // when worker dies (exits), create worker replace cluster.on('exit', function(worker, code, signal){ console.log('cluster: worker %d died exit code %d (%s)', worker.id, code, signal); startworker(); }); } else { // start our app on worker; see meadowlark.js require('./app.js')(); }
this article shows how listen signal (in articles case sigusr2, restart workers). in nutshell like:
process.on("sigusr2", function() { //code disconnect workers, delete cache , restart workers });
my questions is: - sigusr2 best way signal process should reload workers ? if want send additional information ? - sending signal ? os feature can set watch file or directory ? how do ?
note: - rather use os level feature not related node.js. example, posts suggest using node.js specific modules "naught" etc, rather not use "naught". :)
the linux kernel supports file system notification subsystem called inotify
. can use nodejs: https://github.com/c4milo/node-inotify
Comments
Post a Comment