mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-27 20:49:03 +08:00
fix: 解决 Swarm 模式下,启用 live-restore 重启失败的问题 (#564)
This commit is contained in:
parent
cca1406f0f
commit
4c2fb7095d
@ -5,6 +5,7 @@ type DaemonJsonUpdateByFile struct {
|
||||
}
|
||||
|
||||
type DaemonJsonConf struct {
|
||||
IsSwarm bool `json:"isSwarm"`
|
||||
Status string `json:"status"`
|
||||
Version string `json:"version"`
|
||||
Mirrors []string `json:"registryMirrors"`
|
||||
|
@ -49,59 +49,60 @@ func (u *DockerService) LoadDockerStatus() string {
|
||||
}
|
||||
|
||||
func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf {
|
||||
status := constant.StatusRunning
|
||||
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 {
|
||||
status = constant.Stopped
|
||||
data.Status = constant.Stopped
|
||||
}
|
||||
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 {
|
||||
version = itemVersion.Version
|
||||
data.Version = itemVersion.Version
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(constant.DaemonJsonPath); err != nil {
|
||||
return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version}
|
||||
return &data
|
||||
}
|
||||
file, err := os.ReadFile(constant.DaemonJsonPath)
|
||||
if err != nil {
|
||||
return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version}
|
||||
return &data
|
||||
}
|
||||
var conf daemonJsonItem
|
||||
deamonMap := make(map[string]interface{})
|
||||
if err := json.Unmarshal(file, &deamonMap); err != nil {
|
||||
return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version}
|
||||
return &data
|
||||
}
|
||||
arr, err := json.Marshal(deamonMap)
|
||||
if err != nil {
|
||||
return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version}
|
||||
return &data
|
||||
}
|
||||
if err := json.Unmarshal(arr, &conf); err != nil {
|
||||
return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version}
|
||||
return &data
|
||||
}
|
||||
if _, ok := deamonMap["iptables"]; !ok {
|
||||
conf.IPTables = true
|
||||
}
|
||||
driver := "cgroupfs"
|
||||
data.CgroupDriver = "cgroupfs"
|
||||
for _, opt := range conf.ExecOpts {
|
||||
if strings.HasPrefix(opt, "native.cgroupdriver=") {
|
||||
driver = strings.ReplaceAll(opt, "native.cgroupdriver=", "")
|
||||
data.CgroupDriver = strings.ReplaceAll(opt, "native.cgroupdriver=", "")
|
||||
break
|
||||
}
|
||||
}
|
||||
data := dto.DaemonJsonConf{
|
||||
Status: status,
|
||||
Version: version,
|
||||
Mirrors: conf.Mirrors,
|
||||
Registries: conf.Registries,
|
||||
IPTables: conf.IPTables,
|
||||
LiveRestore: conf.LiveRestore,
|
||||
CgroupDriver: driver,
|
||||
}
|
||||
|
||||
data.Mirrors = conf.Mirrors
|
||||
data.Registries = conf.Registries
|
||||
data.IPTables = conf.IPTables
|
||||
data.LiveRestore = conf.LiveRestore
|
||||
return &data
|
||||
}
|
||||
|
||||
|
@ -247,6 +247,7 @@ export namespace Container {
|
||||
operation: string;
|
||||
}
|
||||
export interface DaemonJsonConf {
|
||||
isSwarm: boolean;
|
||||
status: string;
|
||||
version: string;
|
||||
registryMirrors: Array<string>;
|
||||
|
@ -557,7 +557,9 @@ const message = {
|
||||
mirrorsHelper:
|
||||
'If empty, mirror acceleration is disabled. The accelerated URL is used first for the operation, and will skipped when the request times out',
|
||||
registries: 'Insecure registries',
|
||||
liveHelper: 'Whether to close all containers when stopping the docker service',
|
||||
liveHelper:
|
||||
'Allows the running container state to be preserved in case of unexpected shutdown or crash of the Docker daemon',
|
||||
liveWithSwarmHelper: 'live-restore daemon configuration is incompatible with swarm mode.',
|
||||
daemonJsonPath: 'Conf Path',
|
||||
serviceUnavailable: 'Docker service is not started at present, please click',
|
||||
startIn: ' to start',
|
||||
|
@ -564,7 +564,8 @@ const message = {
|
||||
mirrors: '镜像加速',
|
||||
mirrorsHelper: '为空则关闭镜像加速;优先使用加速 URL 执行操作,请求超时将跳过使用默认加速方式',
|
||||
registries: '私有仓库',
|
||||
liveHelper: '停止 docker 服务时,是否关闭所有容器',
|
||||
liveHelper: '允许在 Docker 守护进程发生意外停机或崩溃时保留正在运行的容器状态',
|
||||
liveWithSwarmHelper: 'live-restore 守护进程配置与 Swarm 模式不兼容',
|
||||
daemonJsonPath: '配置路径',
|
||||
serviceUnavailable: '当前未启动 Docker 服务,请在',
|
||||
startIn: '中开启',
|
||||
|
@ -66,8 +66,11 @@
|
||||
<el-switch v-model="form.iptables"></el-switch>
|
||||
</el-form-item>
|
||||
<el-form-item label="live-restore" prop="liveRestore">
|
||||
<el-switch v-model="form.liveRestore"></el-switch>
|
||||
<el-switch :disabled="form.isSwarm" v-model="form.liveRestore"></el-switch>
|
||||
<span class="input-help">{{ $t('container.liveHelper') }}</span>
|
||||
<span v-if="form.isSwarm" class="input-help">
|
||||
{{ $t('container.liveWithSwarmHelper') }}
|
||||
</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="cgroup-driver" prop="cgroupDriver">
|
||||
<el-radio-group v-model="form.cgroupDriver">
|
||||
@ -151,6 +154,7 @@ const extensions = [javascript(), oneDark];
|
||||
const confShowType = ref('base');
|
||||
|
||||
const form = reactive({
|
||||
isSwarm: false,
|
||||
status: '',
|
||||
version: '',
|
||||
mirrors: '',
|
||||
@ -250,6 +254,7 @@ const onSubmitSave = async () => {
|
||||
let itemMirrors = form.mirrors.split('\n');
|
||||
let itemRegistries = form.registries.split('\n');
|
||||
let param = {
|
||||
isSwarm: form.isSwarm,
|
||||
status: form.status,
|
||||
version: '',
|
||||
registryMirrors: itemMirrors.filter(function (el) {
|
||||
@ -294,6 +299,7 @@ const changeMode = async () => {
|
||||
|
||||
const search = async () => {
|
||||
const res = await loadDaemonJson();
|
||||
form.isSwarm = res.data.isSwarm;
|
||||
form.status = res.data.status;
|
||||
form.version = res.data.version;
|
||||
form.cgroupDriver = res.data.cgroupDriver;
|
||||
|
Loading…
Reference in New Issue
Block a user