提交 f088fabc 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

kill sub process on linux

上级 88165066
此差异已折叠。
......@@ -41,7 +41,9 @@
"dependencies": {
"electron-log": "^4.4.6",
"electron-squirrel-startup": "^1.0.0",
"express": "^4.17.3",
"find-process": "^1.4.7",
"ps-tree": "^1.2.0"
"ps-tree": "^1.2.0",
"tree-kill": "^1.2.2"
}
}
......@@ -69,7 +69,6 @@ app.on('window-all-closed', () => {
app.on('before-quit',function(){
logInfo(`>> Event before-quit`)
killZtfServer();
})
app.on('will-quit',function(){
......@@ -78,6 +77,7 @@ app.on('will-quit',function(){
app.on('quit',function(){
logInfo(`>> Event quit`)
killZtfServer();
})
app.on('activate', () => {
......@@ -89,6 +89,3 @@ app.on('activate', () => {
startApp();
}
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.
......@@ -7,6 +7,8 @@ import {logInfo, logErr} from './log';
const DEBUG = process.env.NODE_ENV === 'development';
const isWin = /^win/.test(process.platform);
const isLinux = /^linux/.test(process.platform);
const isMac = /^darwin/.test(process.platform);
let _ztfServerProcess;
export function startZtfServer() {
......@@ -71,6 +73,7 @@ export function startZtfServer() {
reject(spawnError)
});
_ztfServerProcess = cmd;
logInfo(`>> _ztfServerProcess = ${_ztfServerProcess.pid}`)
});
}
......@@ -114,22 +117,6 @@ export function startZtfServer() {
});
}
export function killZtfServer() {
if(!isWin) {
_ztfServerProcess.kill('SIGINT');
kill(_ztfServerProcess.pid);
} else {
const cp = require('child_process');
cp.exec('taskkill /PID ' + _ztfServerProcess.pid + ' /T /F', function (error, stdout, stderr) {
// console.log('stdout: ' + stdout);
// console.log('stderr: ' + stderr);
// if(error !== null) {
// console.log('exec error: ' + error);
// }
});
}
}
let _uiServerApp;
export function getUIServerUrl() {
......@@ -225,27 +212,42 @@ export function getUIServerUrl() {
});
}
const psTree = require('ps-tree');
export function killZtfServer() {
if (isWin) {
logInfo(`>> isWin`);
const cp = require('child_process');
cp.exec('taskkill /PID ' + _ztfServerProcess.pid + ' /T /F',
function (error, stdout, stderr) {
// console.log('stdout: ' + stdout + ', stderr: ' + stderr);
// if(error !== null) console.log('exec error: ' + error);
});
} else if (isMac) {
logInfo(`>> isMac`);
_ztfServerProcess.kill();
} else {
logInfo(`>> isLinux`);
kill(_ztfServerProcess.pid);
}
}
function kill (pid, signal, callback) {
signal = signal || 'SIGKILL';
const psTree = require('ps-tree');
function kill(pid, signal, callback) {
signal = signal || 'SIGKILL';
callback = callback || function () {};
const killTree = true;
if(killTree) {
psTree(pid, function (err, children) {
[pid].concat(
children.map(function (p) {
return p.PID;
})
).forEach(function (tpid) {
try { process.kill(tpid, signal) }
catch (ex) { }
});
callback();
psTree(pid, function (err, children) {
[pid].concat(
children.map(function (p) {
return p.PID;
})
).forEach(function (tpid) {
logInfo(`>> ${tpid}`)
try {
process.kill(tpid, signal)
} catch (ex) {
logErr(`>> ` + ex)
}
});
} else {
try { process.kill(pid, signal) }
catch (ex) { }
callback();
}
});
};
......@@ -98,7 +98,7 @@ func ListLang() (langs []serverDomain.ZentaoLang, err error) {
func ListProduct(projectPath string) (products []serverDomain.ZentaoProduct, err error) {
config := configUtils.LoadByProjectPath(projectPath)
if config.Url == "" {
err = errors.New("请先完成项目配置")
err = errors.New(i118Utils.Sprintf("pls_config_project"))
return
}
......@@ -120,7 +120,6 @@ func ListProduct(projectPath string) (products []serverDomain.ZentaoProduct, err
bytes, err := httpUtils.Get(url)
if err != nil {
err = errors.New("请检查项目配置")
return
}
......@@ -242,7 +241,6 @@ func ListSuiteByProduct(productId int, projectPath string) (suites []serverDomai
bytes, err := httpUtils.Get(url)
if err != nil {
err = errors.New("testsuite-browse fail")
return
}
......@@ -280,7 +278,6 @@ func ListTaskByProduct(productId int, projectPath string) (tasks []serverDomain.
bytes, err := httpUtils.Get(url)
if err != nil {
err = errors.New("testsuite-browse fail")
return
}
......
......@@ -36,7 +36,7 @@ func (c *ZentaoCtrl) ListModule(ctx iris.Context) {
projectPath := ctx.URLParam("currProject")
productId, err := ctx.URLParamInt("productId")
if err != nil {
c.ErrResp(commConsts.ParamErr, err.Error())
ctx.JSON(c.ErrResp(commConsts.ParamErr, err.Error()))
return
}
......@@ -53,7 +53,7 @@ func (c *ZentaoCtrl) ListSuite(ctx iris.Context) {
projectPath := ctx.URLParam("currProject")
productId, err := ctx.URLParamInt("productId")
if err != nil {
c.ErrResp(commConsts.ParamErr, err.Error())
ctx.JSON(c.ErrResp(commConsts.ParamErr, err.Error()))
return
}
......@@ -70,7 +70,7 @@ func (c *ZentaoCtrl) ListTask(ctx iris.Context) {
projectPath := ctx.URLParam("currProject")
productId, err := ctx.URLParamInt("productId")
if err != nil {
c.ErrResp(commConsts.ParamErr, err.Error())
ctx.JSON(c.ErrResp(commConsts.ParamErr, err.Error()))
return
}
......@@ -88,7 +88,7 @@ func (c *ZentaoCtrl) GetDataForBugSubmition(ctx iris.Context) {
req := commDomain.FuncResult{}
if err := ctx.ReadJSON(&req); err != nil {
c.ErrResp(commConsts.ParamErr, err.Error())
ctx.JSON(c.ErrResp(commConsts.ParamErr, err.Error()))
return
}
......
......@@ -15,7 +15,11 @@
},
{
"id": "data_not_init",
"translation": "数据为初始化"
"translation": "数据未初始化"
},
{
"id": "pls_config_project",
"translation": "请先完成项目配置"
},
{
"id": "project_config_err",
......
......@@ -24,6 +24,7 @@ cd client && npm run package-win64 && cd ..
make compile_linux
cd client && npm run package-linux && cd ..
scp -r client/out/ztf-linux-x64/ 192.168.0.114:/home/aaron
make compile_mac
cd client && npm run package-mac && cd ..
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册