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

kill sub process on linux

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