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 3e065930a..be988362a 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',