调整插件安装和软件包安装日志记录方式

This commit is contained in:
dinglili 2024-07-17 14:08:33 +08:00 committed by wangpenglong
parent 9e942f12b5
commit 69f0518bd8
1 changed files with 21 additions and 8 deletions

View File

@ -115,6 +115,8 @@ export class DeployMainService implements IDeployMainService {
startInstallDepWatch = 0;
logger: ILogger;
loggerExt: ILogger;
loggerSoft: ILogger;
constructor(
private userEnv: IProcessEnvironment,
@ -128,6 +130,8 @@ export class DeployMainService implements IDeployMainService {
this.updateConfigDir = installUtils.installConfigDirPre() + "/" + installUtils.getDateDir();
this.reset();
this.logger = this.loggerMainService.createLogger(URI.file(this.installConfig + "/log/instguide.log"));
this.loggerExt = this.loggerMainService.createLogger(URI.file(this.installConfig + "/log/extinstdetail.log"));
this.loggerSoft = this.loggerMainService.createLogger(URI.file(this.installConfig + "/log/softinstdetail.log"));
this.removeListeners();
this.registerListeners();
}
@ -208,7 +212,6 @@ export class DeployMainService implements IDeployMainService {
if (!fs.existsSync(logFile0)) {
fs.mkdirSync(this.installConfig + "/log", { recursive: true });
}
let installCommand = "";
try {
const installItem = this.extDownloadPath + msg.downloadDone;
@ -232,8 +235,8 @@ export class DeployMainService implements IDeployMainService {
}
}
else if (msg.type === 'installPkg') {
const extlogFile = this.installConfig + '/log/extInstall.log';
this.backupLogFile(extlogFile)
// const extlogFile = this.installConfig + '/log/extInstall.log';
// this.backupLogFile(extlogFile)
const extlogFile0 = this.installConfig + '/log/extInstall.1.log';
fs.writeFileSync(extlogFile0, '');
@ -284,11 +287,11 @@ export class DeployMainService implements IDeployMainService {
this.lastLogPosition = 0;
this.lastExtLogPosition = 0;
const logFile = this.installConfig + '/log/install.log';
// const logFile = this.installConfig + '/log/install.log';
const resultFile = this.installConfig + '/resultFile';
const installFile = this.installConfig + '/install.sh';
const logFile0 = this.installConfig + '/log/install.1.log';
this.backupLogFile(logFile);
// this.backupLogFile(logFile);
try {
fs.writeFileSync(resultFile, '');
@ -714,8 +717,9 @@ export class DeployMainService implements IDeployMainService {
data: updatedContent
};
this.logger.debug(`install pkg输出信息更新${updatedContent}`);
// this.logger.debug(`install pkg输出信息更新${updatedContent}`);
if (updatedContent.length > 0)
fs.appendFileSync(this.installConfig + "/log/soft.log", updatedContent);
if (this.DeployWindow)
this.DeployWindow.webContents.send("kylinide.installWizard.msg", installMsg);
}
@ -972,11 +976,13 @@ export class DeployMainService implements IDeployMainService {
try {
const pkexecCommand = `pkexec sudo bash ${scriptPath}`;
this.logger.info(`执行命令 ${pkexecCommand}`);
this.loggerSoft.info(`执行命令 ${pkexecCommand}`);
this.installProcessId = spawn(pkexecCommand, { shell: true, stdio: 'inherit' });
this.installProcessId.on('exit', (code, signal) => {
this.flagPkexec++;
this.logger.info(`执行命令 ${pkexecCommand} 结束,退出码:${code}`);
this.loggerSoft.info(`执行命令 ${pkexecCommand} 结束,退出码:${code}`);
if (code == 127) {
//授权失败,结束安装。
if (this.DeployWindow) {
@ -987,6 +993,7 @@ export class DeployMainService implements IDeployMainService {
});
} catch (error) {
this.logger.error(`执行脚本时出错: ${error.message}`);
this.loggerSoft.error(`执行脚本时出错: ${error.message}`);
// return false;
}
}
@ -1031,11 +1038,15 @@ export class DeployMainService implements IDeployMainService {
const extlogFile = this.installConfig + '/log/extInstall.1.log';
let ret: { stdout: string, stderr: string } = await this.spawnCommand(installCommand) as { stdout: string; stderr: string; };
if (ret.stdout)
if (ret.stdout) {
fs.appendFileSync(extlogFile, ret.stdout);
this.loggerExt.info(ret.stdout);
}
// if (ret.stderr)
// fs.appendFileSync(extlogFile, ret.stderr);
this.logger.info(`执行命令成功 ${installCommand}`);
this.loggerExt.info(`执行命令成功 ${installCommand}`);
const installMsg = {
type: "extInstalled",
@ -1053,6 +1064,8 @@ export class DeployMainService implements IDeployMainService {
fs.appendFileSync(extlogFile, '\n');
fs.appendFileSync(extlogFile, error.message);
fs.appendFileSync(extlogFile, '\n');
this.loggerExt.info(`执行命令失败 ${installCommand}`);
this.loggerExt.info(error.message);
const installMsg = {
type: "extInstalledFail",
extFileName: msg.downloadDone,