當我想在我的節點上運行服務apache2狀態時,我注意到非常奇怪的行爲。這是代碼:如何檢查停止服務的服務狀態
app.post('/getStatus', jsonParser, function(req,res){
exec("service apache2 status", function(err, stdout){
if(err) throw err;
var statuspmtatmp = /Active: [a-z]* [\(][a-z]*[\)]/g.exec(stdout.toString())[0];
res.json(statuspmtatmp);
});
});
當我運行時的apache運行一切正常,但是當我停止Apache和他們我嘗試檢查狀態,我得到錯誤的命令:
Error: Command failed: /bin/sh -c service apache2 status
at ChildProcess.exithandler (child_process.js:213:12)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:821:16)
at Socket.<anonymous> (internal/child_process.js:319:11)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at Pipe._onclose (net.js:469:12)
什麼是錯的?爲什麼當Apache運行一切正常?
爲什麼在這一行?爲什麼不通過我看到的粗壯的代碼我有信息說服務被甩了? – cyprian
我更新了我的回答 – aaron0207
工作?我添加了一些清晰的答案,也許現在更清楚 – aaron0207