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