mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-03 03:55:58 +08:00
fix: docker 状态判断逻辑修改 (#1073)
This commit is contained in:
parent
8c4016792b
commit
72bc99bddc
7 changed files with 47 additions and 101 deletions
|
@ -16,7 +16,5 @@ type DaemonJsonConf struct {
|
|||
}
|
||||
|
||||
type DockerOperation struct {
|
||||
StopSocket bool `json:"stopSocket"`
|
||||
StopService bool `json:"stopService"`
|
||||
Operation string `json:"operation" validate:"required,oneof=start restart stop"`
|
||||
Operation string `json:"operation" validate:"required,oneof=start restart stop"`
|
||||
}
|
||||
|
|
|
@ -39,37 +39,40 @@ type daemonJsonItem struct {
|
|||
}
|
||||
|
||||
func (u *DockerService) LoadDockerStatus() string {
|
||||
status := constant.StatusRunning
|
||||
stdout, err := cmd.Exec("systemctl is-active docker")
|
||||
if string(stdout) != "active\n" || err != nil {
|
||||
status = constant.Stopped
|
||||
client, err := docker.NewDockerClient()
|
||||
if err != nil {
|
||||
return constant.Stopped
|
||||
}
|
||||
if _, err := client.Ping(context.Background()); err != nil {
|
||||
return constant.Stopped
|
||||
}
|
||||
|
||||
return status
|
||||
return constant.StatusRunning
|
||||
}
|
||||
|
||||
func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf {
|
||||
ctx := context.Background()
|
||||
var data dto.DaemonJsonConf
|
||||
data.IPTables = true
|
||||
data.Status = constant.StatusRunning
|
||||
stdout, err := cmd.Exec("systemctl is-active docker")
|
||||
if string(stdout) != "active\n" || err != nil {
|
||||
data.Version = "-"
|
||||
client, err := docker.NewDockerClient()
|
||||
if err != nil {
|
||||
data.Status = constant.Stopped
|
||||
} else {
|
||||
if _, err := client.Ping(ctx); err != nil {
|
||||
data.Status = constant.Stopped
|
||||
}
|
||||
itemVersion, err := client.ServerVersion(ctx)
|
||||
if err == nil {
|
||||
data.Version = itemVersion.Version
|
||||
}
|
||||
}
|
||||
data.IsSwarm = false
|
||||
stdout2, _ := cmd.Exec("docker info | grep Swarm")
|
||||
if string(stdout2) == " Swarm: active\n" {
|
||||
data.IsSwarm = true
|
||||
}
|
||||
data.Version = "-"
|
||||
client, err := docker.NewDockerClient()
|
||||
if err == nil {
|
||||
ctx := context.Background()
|
||||
itemVersion, err := client.ServerVersion(ctx)
|
||||
if err == nil {
|
||||
data.Version = itemVersion.Version
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(constant.DaemonJsonPath); err != nil {
|
||||
return &data
|
||||
}
|
||||
|
@ -206,10 +209,7 @@ func (u *DockerService) UpdateConfByFile(req dto.DaemonJsonUpdateByFile) error {
|
|||
func (u *DockerService) OperateDocker(req dto.DockerOperation) error {
|
||||
service := "docker"
|
||||
if req.Operation == "stop" {
|
||||
service = "docker.service"
|
||||
if req.StopSocket {
|
||||
service = "docker.socket"
|
||||
}
|
||||
service = "docker.socket"
|
||||
}
|
||||
stdout, err := cmd.Execf("systemctl %s %s ", req.Operation, service)
|
||||
if err != nil {
|
||||
|
|
|
@ -247,11 +247,6 @@ export namespace Container {
|
|||
export interface DaemonJsonUpdateByFile {
|
||||
file: string;
|
||||
}
|
||||
export interface DockerOperate {
|
||||
stopSocket: boolean;
|
||||
stopService: boolean;
|
||||
operation: string;
|
||||
}
|
||||
export interface DaemonJsonConf {
|
||||
isSwarm: boolean;
|
||||
status: string;
|
||||
|
|
|
@ -130,8 +130,8 @@ export const composeUpdate = (params: Container.ComposeUpdate) => {
|
|||
};
|
||||
|
||||
// docker
|
||||
export const dockerOperate = (params: Container.DockerOperate) => {
|
||||
return http.post(`/containers/docker/operate`, params);
|
||||
export const dockerOperate = (operation: string) => {
|
||||
return http.post(`/containers/docker/operate`, { operation: operation });
|
||||
};
|
||||
export const loadDaemonJson = () => {
|
||||
return http.get<Container.DaemonJsonConf>(`/containers/daemonjson`);
|
||||
|
|
|
@ -565,10 +565,7 @@ const message = {
|
|||
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',
|
||||
operatorStatusHelper: 'This action will {0} Docker service, do you want to continue?',
|
||||
dockerStatus: 'Docker Service',
|
||||
daemonJsonPathHelper: 'Ensure that the configuration path is the same as that specified in docker.service.',
|
||||
mirrors: 'Registry mirrors',
|
||||
|
|
|
@ -580,10 +580,7 @@ const message = {
|
|||
composeOperatorHelper: '将对 {0} 进行 {1} 操作,是否继续?',
|
||||
|
||||
setting: '配置',
|
||||
stopHelper: 'docker 服务包括 docker.service 和 docker.socket 两部分: ',
|
||||
stopHelper2:
|
||||
'停止 docker.service 时 docker.socket 将保持监听状态,当监听到 docker 命令请求时,会将 docker.service 重新拉起。',
|
||||
stopHelper3: '停止 docker.socket 将导致 docker.service 服务不可用',
|
||||
operatorStatusHelper: '此操作将{0}Docker 服务,是否继续?',
|
||||
dockerStatus: 'Docker 服务',
|
||||
daemonJsonPathHelper: '请保证配置路径与 docker.service 中指定的配置路径保持一致。',
|
||||
mirrors: '镜像加速',
|
||||
|
|
|
@ -119,24 +119,6 @@
|
|||
</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>
|
||||
|
||||
<el-dialog
|
||||
v-model="iptablesVisiable"
|
||||
:title="$t('container.iptablesDisable')"
|
||||
|
@ -165,7 +147,7 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { FormInstance } from 'element-plus';
|
||||
import { ElMessageBox, FormInstance } from 'element-plus';
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import { Codemirror } from 'vue-codemirror';
|
||||
import LayoutContent from '@/layout/layout-content.vue';
|
||||
|
@ -202,10 +184,6 @@ const formRef = ref<FormInstance>();
|
|||
const dockerConf = ref();
|
||||
const confirmDialogRef = ref();
|
||||
|
||||
const stopVisiable = ref();
|
||||
const stopSocket = ref();
|
||||
const stopService = ref();
|
||||
|
||||
const iptablesVisiable = ref();
|
||||
|
||||
const onSave = async (formEl: FormInstance | undefined) => {
|
||||
|
@ -246,46 +224,27 @@ const onSaveIptables = (status: boolean) => {
|
|||
};
|
||||
|
||||
const onOperator = async (operation: string) => {
|
||||
if (operation === 'stop') {
|
||||
stopVisiable.value = true;
|
||||
return;
|
||||
}
|
||||
let param = {
|
||||
stopService: false,
|
||||
stopSocket: false,
|
||||
operation: operation,
|
||||
};
|
||||
loading.value = true;
|
||||
await dockerOperate(param)
|
||||
.then(() => {
|
||||
loading.value = false;
|
||||
search();
|
||||
changeMode();
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
};
|
||||
|
||||
const submitStop = async () => {
|
||||
let param = {
|
||||
stopService: stopService.value,
|
||||
stopSocket: stopSocket.value,
|
||||
operation: 'stop',
|
||||
};
|
||||
loading.value = true;
|
||||
await dockerOperate(param)
|
||||
.then(() => {
|
||||
loading.value = false;
|
||||
stopVisiable.value = false;
|
||||
search();
|
||||
changeMode();
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
ElMessageBox.confirm(
|
||||
i18n.global.t('container.operatorStatusHelper', [i18n.global.t('commons.button.' + operation)]),
|
||||
i18n.global.t('commons.table.operate'),
|
||||
{
|
||||
confirmButtonText: i18n.global.t('commons.button.confirm'),
|
||||
cancelButtonText: i18n.global.t('commons.button.cancel'),
|
||||
type: 'info',
|
||||
},
|
||||
).then(async () => {
|
||||
loading.value = true;
|
||||
await dockerOperate(operation)
|
||||
.then(() => {
|
||||
loading.value = false;
|
||||
search();
|
||||
changeMode();
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const onSubmitSave = async () => {
|
||||
|
|
Loading…
Add table
Reference in a new issue