kill port在main中, 防止refresh时kill掉自己

This commit is contained in:
life
2015-09-24 12:56:34 +08:00
parent b22b859430
commit 59537e398b
3 changed files with 29 additions and 6 deletions

View File

@@ -1 +1 @@
{"version":"0.6.4","updatedTime":"2015-09-22T07:11:51.505Z"}
{"version":"0.7","updatedTime":"2015-09-22T07:11:51.505Z"}

View File

@@ -209,7 +209,30 @@ function setMenu() {
Menu.setApplicationMenu(menu); // Must be called within app.on('ready', function(){ ... });
}
var child_process = require('child_process');
function killPort(callback) {
var port = '8912';
if (process.platform.toLowerCase().indexOf('win') === 0) {
// & EXIT 表示只循环一次
// Leanote会有两个pid绑定端口, 另一个和electron相关, kill掉也会把自己kill掉
var sh1 = 'FOR /F "tokens=4 delims= " %P IN (\'netstat -a -n -o ^| findstr :' + port + '\') DO (TaskKill.exe /F /PID %P) & Exit';
var sh2 = 'FOR /F "tokens=5 delims= " %P IN (\'netstat -a -n -o ^| findstr :' + port + '\') DO (TaskKill.exe /F /PID %P) & Exit';
child_process.exec(sh1, function () {
child_process.exec(sh2, callback);
});
}
else {
var sh = 'kill -9 $(lsof -i:' + port + ' -t)';
child_process.exec(sh, callback);
}
}
function openIt() {
killPort(_openIt);
}
function _openIt() {
// console.log(arguments);
// app.getPath('appData');
// var Evt = require('evt');

10
src/node_modules/server.js generated vendored
View File

@@ -104,10 +104,10 @@ var Server = {
child_process.exec(sh, callback);
}
}
killPort(function (error, stdout, stderr) {
if (error !== null) {
console.log('kill port error: ' + error);
}
// killPort(function (error, stdout, stderr) {
// if (error !== null) {
// console.log('kill port error: ' + error);
// }
server.listen(Evt.port);
console.log("Server runing at port: " + Evt.port + ".");
@@ -116,7 +116,7 @@ var Server = {
me._started = true;
me.server = server;
});
// });
},
// 关闭服务