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

kill ztf process

上级 cc75f102
......@@ -43,6 +43,7 @@
"electron-squirrel-startup": "^1.0.0",
"express": "^4.17.3",
"find-process": "^1.4.7",
"kill-port-process": "^3.0.1",
"ps-tree": "^1.2.0",
"tree-kill": "^1.2.2"
}
......
export const portClient = 55231
export const portServer = 55232
export const uuid = 'ZTF@1CF17A46-B136-4AEB-96B4-F21C8200EF5A~'
......@@ -3,54 +3,23 @@ import cp, {execSync, spawn} from 'child_process';
import os from 'os';
import {app} from 'electron';
import express from 'express';
const psTree = require('ps-tree');
const { killPortProcess } = require('kill-port-process');
import {portClient, portServer, uuid} from './consts';
import {logInfo, logErr} from './log';
const psTree = require('ps-tree');
const DEBUG = process.env.NODE_ENV === 'development';
const isWin = /^win/.test(process.platform);
const isMac = /^darwin/.test(process.platform);
const uuid = 'ZTF@1CF17A46-B136-4AEB-96B4-F21C8200EF5A~'
const port = 8085
let _ztfServerProcess;
let _ztfSubProcessIds = [];
export function checkZtfPort() {
let cmd = ''
if (!isWin) {
cmd = `lsof -i:${port} | grep :${port}`
} else {
cmd = `netstat -aon`
}
const cp = require('child_process');
const stdout = cp.execSync(cmd).toString().trim()
const msg = `exec ${cmd}, stdout: ${stdout}`
console.log(msg);
logInfo(msg)
if (stdout.indexOf(':' + port) > -1) {
if (stdout.indexOf(uuid) < 0) {
const msg = 'Port ${port} is used by another process. exit.'
console.log(msg);
logErr(msg);
return false
}
const msg = 'Port ${port} is used by ztf process. kill previous one.'
console.log(msg);
logInfo(msg);
killZtfServer()
} else {
return true
}
}
export function startZtfServer() {
const pass = checkZtfPort()
if (!pass) {
return
}
(async () => {
await killPortProcess([portClient, portServer])
})();
if (process.env.SKIP_SERVER) {
logInfo(`>> Skip to start ZTF Server by env "SKIP_SERVER=${process.env.SKIP_SERVER}".`);
......@@ -72,8 +41,8 @@ export function startZtfServer() {
}
return new Promise((resolve, reject) => {
const cwd = process.env.SERVER_CWD_PATH || path.dirname(serverExePath);
logInfo(`>> Starting ZTF Server from exe path with command "${serverExePath} -P 8085" in "${cwd}"...`);
const cmd = spawn(serverExePath, ['-p', '8085', "-uuid", uuid], {
logInfo(`>> Starting ZTF Server from exe path with command "${serverExePath} -P ${portServer}" in "${cwd}"...`);
const cmd = spawn(serverExePath, ['-p', portServer, "-uuid", uuid], {
cwd,
shell: true,
});
......@@ -187,7 +156,7 @@ export function getUIServerUrl() {
uiServerUrl = path.resolve(app.getAppPath(), uiServerUrl);
}
const port = process.env.UI_SERVER_PORT || 8000;
const port = process.env.UI_SERVER_PORT || portClient;
logInfo(`>> Starting UI serer at ${uiServerUrl} with port ${port}`);
const uiServer = express();
......
......@@ -2,10 +2,10 @@
NODE_ENV = 'production'
# devServer port
VUE_APP_PORT=8000
VUE_APP_PORT=55231
# mock 是否开启 true|false , development环境有效
VUE_APP_MOCK = false
#api接口域名
VUE_APP_APIHOST = http://127.0.0.1:8085/api/v1
VUE_APP_APIHOST = http://127.0.0.1:55232/api/v1
......@@ -2,7 +2,7 @@
const bodyParser = require('body-parser')
const { NODE_ENV, VUE_APP_PORT, VUE_APP_MOCK } = process.env;
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
// const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
module.exports = {
publicPath: '/',
......@@ -75,11 +75,11 @@ module.exports = {
config.resolve.alias.set('vue-i18n', 'vue-i18n/dist/vue-i18n.cjs.js')
config.plugin('monaco-editor').use(MonacoWebpackPlugin, [
{
// Languages are loaded on demand at runtime
languages: ['json', 'javascript', 'html', 'xml']
}
])
// config.plugin('monaco-editor').use(MonacoWebpackPlugin, [
// {
// // Languages are loaded on demand at runtime
// languages: ['json', 'javascript', 'html', 'xml']
// }
// ])
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册