From 6da64f2c8fb0d279f71abda205cfe44303801dc1 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Mon, 21 Aug 2023 17:00:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=B8=85=E7=A9=BA?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E6=97=A5=E5=BF=97=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=20CPU=20=E5=8D=A0=E7=94=A8=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#2019)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #1999 --- backend/app/service/container.go | 14 +++++++++++--- frontend/src/components/container-log/index.vue | 2 +- frontend/src/lang/modules/en.ts | 2 ++ frontend/src/lang/modules/tw.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + .../src/views/container/container/log/index.vue | 2 +- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/backend/app/service/container.go b/backend/app/service/container.go index 085bd19dc..d79f0234b 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -531,11 +531,15 @@ func (u *ContainerService) ContainerLogClean(req dto.OperationWithName) error { if err != nil { return err } - container, err := client.ContainerInspect(context.Background(), req.Name) + ctx := context.Background() + containerItem, err := client.ContainerInspect(ctx, req.Name) if err != nil { return err } - file, err := os.OpenFile(container.LogPath, os.O_RDWR|os.O_CREATE, 0666) + if err := client.ContainerStop(ctx, containerItem.ID, container.StopOptions{}); err != nil { + return err + } + file, err := os.OpenFile(containerItem.LogPath, os.O_RDWR|os.O_CREATE, 0666) if err != nil { return err } @@ -545,10 +549,14 @@ func (u *ContainerService) ContainerLogClean(req dto.OperationWithName) error { } _, _ = file.Seek(0, 0) - files, _ := filepath.Glob(fmt.Sprintf("%s.*", container.LogPath)) + files, _ := filepath.Glob(fmt.Sprintf("%s.*", containerItem.LogPath)) for _, file := range files { _ = os.Remove(file) } + + if err := client.ContainerStart(ctx, containerItem.ID, types.ContainerStartOptions{}); err != nil { + return err + } return nil } diff --git a/frontend/src/components/container-log/index.vue b/frontend/src/components/container-log/index.vue index 9c1e37880..3ccd7532e 100644 --- a/frontend/src/components/container-log/index.vue +++ b/frontend/src/components/container-log/index.vue @@ -130,7 +130,7 @@ const acceptParams = (props: DialogProps): void => { }; const onClean = async () => { - ElMessageBox.confirm(i18n.global.t('commons.msg.clean'), i18n.global.t('container.cleanLog'), { + ElMessageBox.confirm(i18n.global.t('container.cleanLogHelper'), i18n.global.t('container.cleanLog'), { confirmButtonText: i18n.global.t('commons.button.confirm'), cancelButtonText: i18n.global.t('commons.button.cancel'), type: 'info', diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index b921ad3f6..200cbd421 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -507,6 +507,8 @@ const message = { lastHour: 'Last Hour', last10Min: 'Last 10 Minutes', cleanLog: 'Clean log', + cleanLogHelper: + 'Clearing logs requires restarting the container, and this operation cannot be rolled back. Do you want to continue?', newName: 'New name', source: 'Resource rate', cpuShare: 'CPU Share', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 3ae0e6691..71deff2fb 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -496,6 +496,7 @@ const message = { lastHour: '最近 1 小時', last10Min: '最近 10 分鐘', cleanLog: '清空日誌', + cleanLogHelper: '清空日誌需要重啟容器,該操作無法回滾,是否繼續?', newName: '新名稱', source: '資源使用率', cpuShare: 'CPU 權重', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index b5f1f6be7..0dc3e03c9 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -496,6 +496,7 @@ const message = { lastHour: '最近 1 小时', last10Min: '最近 10 分钟', cleanLog: '清空日志', + cleanLogHelper: '清空日志需要重启容器,该操作无法回滚,是否继续?', newName: '新名称', source: '资源使用率', cpuShare: 'CPU 权重', diff --git a/frontend/src/views/container/container/log/index.vue b/frontend/src/views/container/container/log/index.vue index d32d4d8ca..9ca0e55b8 100644 --- a/frontend/src/views/container/container/log/index.vue +++ b/frontend/src/views/container/container/log/index.vue @@ -161,7 +161,7 @@ const onDownload = async () => { }; const onClean = async () => { - ElMessageBox.confirm(i18n.global.t('commons.msg.clean'), i18n.global.t('container.cleanLog'), { + ElMessageBox.confirm(i18n.global.t('container.cleanLogHelper'), i18n.global.t('container.cleanLog'), { confirmButtonText: i18n.global.t('commons.button.confirm'), cancelButtonText: i18n.global.t('commons.button.cancel'), type: 'info',