2014-02-21 10 views
3

IIS 비동기를 시작하는 작업이 있고 IIS를 중지하려면 잡동사니 이벤트를해야합니다.출구를 기다리는 잡담 작업

나는 ctrl-c을 누른 다음 해당 이벤트를 발생시킬 때까지 기다리는 작업을하고 싶습니다.

grunt.registerTask("killiis", function(){ 
    process.stdin.resume(); 
    var done = this.async(); 
    grunt.log.writeln('Waiting...');  

    process.on('SIGINT', function() { 
     grunt.event.emit('iis.kill'); 
     grunt.log.writeln('Got SIGINT. Press Control-D to exit.'); 
     done(); 
    }); 
}); 

작업이 성공적으로 꿀꿀 거리는 소리를 중지하지만, 제대로 이벤트를 전송하지 않습니다

나는이 일을 시도했습니다.

답변

3

SIGINT 핸들러는 Node.js에서 작동하지만 그루트에서는 작동하지 않습니다 (이유를 모르겠습니다). 내가 수동으로 ctrl+creadline 모듈을 사용하고 exit 이벤트를 수신 핸들 :

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 
} 

는 또한 내가 콘솔 창 닫기 또는 ctrl+break를 처리 할 수 ​​ SIGINT, SIGHUPSIGBREAK 신호를 듣고 제안 (아무도 ㅎ, 그것을 사용하는 경우). 당신은 또한 응용 프로그램을 중지 할 때이 핸들러에서 process.exit() 전화 : https://github.com/whyleee/grunt-iisexpress :

process.on('exit', killIis); 
process.on('SIGINT', killIisAndExit); 
process.on('SIGHUP', killIisAndExit); 
process.on('SIGBREAK', killIisAndExit); 

내가 출구에서 IIS를 죽이고 grunt-iisexpress의 포크가 있습니다.

+0

이 정확한지는 모르겠지만, 지금은 꽤 오랫동안 이것을 보지 않았기 때문에 현재 확인할 수 없습니다. 만약 내가이 레포로 돌아 가면, 내가 보게 될거야. 환호 – MrJD

0

나는 whyleee의 제안을 시도했지만, 그 자체를 종료하기 전에 grunt이 정리 프로세스가 종료되기를 기다리지 않고 있음을 발견했습니다.

나를위한 해결책은 this article을 기반으로했습니다.

module.exports = function(grunt) { 
    var exec, readline, shuttingDown, stdInterface; 
    shuttingDown = false; 
    readline = require("readline"); 
    exec = require("child_process").exec; 
    // other grunt requires/task loads, including a "cleanup" task ... 
    stdInterface = readline.createInterface({ 
    input: process.stdin, 
    output: process.stdout 
    }); 
    stdInterface.on("SIGINT", function() { 
    var child; 
    if (shuttingDown) { 
     return; 
    } 
    shuttingDown = true; 
    console.info("Cleaning up ..."); 
    child = exec("grunt cleanup", function(err, stdout, stderr) { 
     console.info(stdout); 
     process.exit(err ? 1 : 0); 
    }); 
    }); 
    // other grunt config ... 
}; 
+0

링크가 더 이상 작동하지 않는다. 404 오류. –