fix: docker 关闭增加 socket、service 选项

pull/201/head
ssongliu 2023-03-11 23:44:16 +08:00 committed by ssongliu
parent c4e54b2f0f
commit c86822fd3d
7 changed files with 69 additions and 2 deletions

View File

@ -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"`
}

View File

@ -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))
}

View File

@ -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']

View File

@ -241,6 +241,8 @@ export namespace Container {
file: string;
}
export interface DockerOperate {
stopSocket: boolean;
stopService: boolean;
operation: string;
}
export interface DaemonJsonConf {

View File

@ -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',

View File

@ -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: '',

View File

@ -102,6 +102,24 @@
</template>
</LayoutContent>
<el-dialog v-model="stopVisiable" :title="$t('app.checkTitle')" width="50%" :destroy-on-close="true">
<el-alert :closable="false">
{{ $t('container.stopHelper') }}
<li>{{ $t('container.stopHelper2') }}</li>
<li>{{ $t('container.stopHelper3') }}</li>
</el-alert>
<div style="margin-top: 10px">
<el-checkbox v-model="stopService" label="docker.service" />
</div>
<div class="stopCheckbox"><el-checkbox v-model="stopSocket" label="docker.socket" /></div>
<template #footer>
<span class="dialog-footer">
<el-button @click="stopVisiable = false">{{ $t('commons.button.cancel') }}</el-button>
<el-button type="primary" @click="submitStop">{{ $t('commons.button.confirm') }}</el-button>
</span>
</template>
</el-dialog>
<ConfirmDialog ref="confirmDialogRef" @confirm="onSubmitSave"></ConfirmDialog>
</div>
</template>
@ -142,6 +160,10 @@ const formRef = ref<FormInstance>();
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 };