SIGINT
handlers work in Node.js, but not in Grunt (I don't know why). I handle ctrl+c
manually using readline
module and listen to exit
event:
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('SIGINT', function() {
process.emit('SIGINT');
});
process.on('exit', killIis);
function killIis() {
// kill it
}
Additionally I suggest to listen to SIGINT
, SIGHUP
and SIGBREAK
signals to handle console window close or ctrl+break
(if anybody use it, heh). Call process.exit()
in these handlers when you also want to stop the app:
process.on('exit', killIis);
process.on('SIGINT', killIisAndExit);
process.on('SIGHUP', killIisAndExit);
process.on('SIGBREAK', killIisAndExit);
I have a fork of grunt-iisexpress
that kills IIS on exit: https://github.com/whyleee/grunt-iisexpress.