diff --git a/backend/app/dto/docker.go b/backend/app/dto/docker.go index dc630b924..42bddcc15 100644 --- a/backend/app/dto/docker.go +++ b/backend/app/dto/docker.go @@ -14,5 +14,7 @@ type DaemonJsonConf struct { } type DockerOperation struct { - Operation string `json:"operation" validate:"required,oneof=start restart stop"` + StopSocket bool `json:"stopSocket"` + StopService bool `json:"stopService"` + Operation string `json:"operation" validate:"required,oneof=start restart stop"` } diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index 8d92a80a7..f984097b5 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -180,7 +180,14 @@ func (u *DockerService) UpdateConfByFile(req dto.DaemonJsonUpdateByFile) error { } func (u *DockerService) OperateDocker(req dto.DockerOperation) error { - stdout, err := cmd.Execf("systemctl %s docker ", req.Operation) + service := "docker" + if req.Operation == "stop" { + service = "docker.service" + if req.StopSocket { + service = "docker.socket" + } + } + stdout, err := cmd.Execf("systemctl %s %s ", req.Operation, service) if err != nil { return errors.New(string(stdout)) } diff --git a/frontend/components.d.ts b/frontend/components.d.ts index 3889f0344..67a7f2214 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -19,6 +19,7 @@ declare module 'vue' { ContainerLog: typeof import('./src/components/container-log/index.vue')['default'] DrawerHeader: typeof import('./src/components/drawer-header/index.vue')['default'] ElAlert: typeof import('element-plus/es')['ElAlert'] + ElAlter: typeof import('element-plus/es')['ElAlter'] ElAside: typeof import('element-plus/es')['ElAside'] ElAvatar: typeof import('element-plus/es')['ElAvatar'] ElBadge: typeof import('element-plus/es')['ElBadge'] diff --git a/frontend/src/api/interface/container.ts b/frontend/src/api/interface/container.ts index a5fa00af0..ac3170e38 100644 --- a/frontend/src/api/interface/container.ts +++ b/frontend/src/api/interface/container.ts @@ -241,6 +241,8 @@ export namespace Container { file: string; } export interface DockerOperate { + stopSocket: boolean; + stopService: boolean; operation: string; } export interface DaemonJsonConf { diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index e485b34a7..0552c559f 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -529,6 +529,10 @@ export default { composeOperatorHelper: '{1} operation will be performed on {0}. Do you want to continue?', setting: 'Setting', + stopHelper: 'docker service includes docker.service and docker.socket: ', + stopHelper2: + 'When docker.service is stopped, Docker.socket will keep listening state. When docker command request is listened, The docker.service will be pulled up again.', + stopHelper3: 'Stopping docker.socket will make the docker.service service unavailable', dockerStatus: 'Docker Service', daemonJsonPathHelper: 'Ensure that the configuration path is the same as that specified in docker.service.', mirrors: 'Registry mirrors', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 4695f8c63..aaba62f3a 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -541,6 +541,10 @@ export default { composeOperatorHelper: '将对 {0} 进行 {1} 操作,是否继续?', setting: '配置', + stopHelper: 'docker 服务包括 docker.service 和 docker.socket 两部分: ', + stopHelper2: + '停止 docker.service 时 docker.socket 将保持监听状态,当监听到 docker 命令请求时,会将 docker.service 重新拉起。', + stopHelper3: '停止 docker.socket 将导致 docker.service 服务不可用', dockerStatus: 'Docker 服务', daemonJsonPathHelper: '请保证配置路径与 docker.service 中指定的配置路径保持一致。', mirrors: '镜像加速', diff --git a/frontend/src/views/container/setting/index.vue b/frontend/src/views/container/setting/index.vue index 06c68f798..80d56b3e3 100644 --- a/frontend/src/views/container/setting/index.vue +++ b/frontend/src/views/container/setting/index.vue @@ -102,6 +102,24 @@ + + + {{ $t('container.stopHelper') }} +
  • {{ $t('container.stopHelper2') }}
  • +
  • {{ $t('container.stopHelper3') }}
  • +
    +
    + +
    +
    + +
    + @@ -142,6 +160,10 @@ const formRef = ref(); const dockerConf = ref(); const confirmDialogRef = ref(); +const stopVisiable = ref(); +const stopSocket = ref(); +const stopService = ref(); + const onSave = async (formEl: FormInstance | undefined) => { if (!formEl) return; formEl.validate(async (valid) => { @@ -165,7 +187,13 @@ const onSaveFile = async () => { }; const onOperator = async (operation: string) => { + if (operation === 'stop') { + stopVisiable.value = true; + return; + } let param = { + stopService: false, + stopSocket: false, operation: operation, }; loading.value = true; @@ -181,6 +209,25 @@ const onOperator = async (operation: string) => { }); }; +const submitStop = async () => { + let param = { + stopService: stopService.value, + stopSocket: stopSocket.value, + operation: 'stop', + }; + loading.value = true; + await dockerOperate(param) + .then(() => { + loading.value = false; + search(); + changeMode(); + MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); + }) + .catch(() => { + loading.value = false; + }); +}; + const onSubmitSave = async () => { if (confShowType.value === 'all') { let param = { file: dockerConf.value };