Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
xianyunleo committed May 29, 2024
1 parent 913bf43 commit 87ce8ff
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/main/core/ServerControl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isDev, isWindows } from '@/main/utils/utils'
import { devConsoleLog } from '@/main/utils/utils'
import ProcessExtend from "@/main/utils/ProcessExtend";
import Software from "@/main/core/software/Software";
import { parseTemplateStrings} from "@/shared/utils/utils";
Expand All @@ -14,16 +14,16 @@ export default class ServerControl {
*/
static async start(item) {
const workPath = Software.getPath(item) //服务目录
const serverProcessPath = this.getControlProcessPath(item)
const ctrlProcessPath = this.getControlProcessPath(item)
const options = { cwd: workPath, detached: true }

if (item.ShellServerProcess) {
options.detached = false
options.shell = true //使用shell,childProcess返回的pid是shell的pid
}

if (!await FileUtil.Exists(serverProcessPath)) {
throw new Error(`${serverProcessPath} 文件不存在!`);
if (!await FileUtil.Exists(ctrlProcessPath)) {
throw new Error(`${ctrlProcessPath} 文件不存在!`);
}

let args = []
Expand All @@ -34,20 +34,20 @@ export default class ServerControl {
item.isRunning = true
item.errMsg = ''

const childProcess = child_process.spawn(serverProcessPath, args, options);
const childProcess = child_process.spawn(ctrlProcessPath, args, options);

childProcess.stderr.on('data', (data) => {
console.log('stderr data',data?.toString())
item.errMsg = data?.toString();
});
devConsoleLog('stderr data', data?.toString())
item.errMsg = data?.toString()
})

childProcess.on('close', (code) => {
if (isDev) console.log(`${Path.GetBaseName(serverProcessPath)},exit code ${code}`);
item.isRunning = false;
});
devConsoleLog(`${Path.GetBaseName(ctrlProcessPath)},exit code ${code}`)
item.isRunning = false
})

if (isDev) console.log('ServerControl start command:', `${serverProcessPath} ${args.join(' ')}`);
if (isDev) console.log(`${Path.GetBaseName(serverProcessPath)},pid ${childProcess.pid}`);
devConsoleLog('ServerControl start command:', `${ctrlProcessPath} ${args.join(' ')}`)
devConsoleLog(`${Path.GetBaseName(ctrlProcessPath)},pid ${childProcess.pid}`)

item.pid = childProcess.pid;
}
Expand Down Expand Up @@ -75,8 +75,8 @@ export default class ServerControl {
options.detached = false
options.shell = true //使用shell,childProcess返回的pid是shell的pid
}
const serverProcessPath = this.getControlProcessPath(item)
child_process.spawn(serverProcessPath, args, options)
const ctrlProcessPath = this.getControlProcessPath(item)
child_process.spawn(ctrlProcessPath, args, options)
} else {
await ProcessExtend.kill(item.pid)
}
Expand Down

0 comments on commit 87ce8ff

Please sign in to comment.