mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-09-12 17:46:20 +08:00
fix: 快照增加 docker 服务成功等待逻辑
This commit is contained in:
parent
f3d6f4ee9b
commit
7266e2afbd
2 changed files with 27 additions and 22 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
||||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/docker"
|
"github.com/1Panel-dev/1Panel/backend/utils/docker"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -40,11 +41,10 @@ type daemonJsonItem struct {
|
||||||
|
|
||||||
func (u *DockerService) LoadDockerStatus() string {
|
func (u *DockerService) LoadDockerStatus() string {
|
||||||
status := constant.StatusRunning
|
status := constant.StatusRunning
|
||||||
// cmd := exec.Command("systemctl", "is-active", "docker")
|
stdout, err := cmd.Exec("systemctl is-active docker")
|
||||||
// stdout, err := cmd.CombinedOutput()
|
if string(stdout) != "active\n" || err != nil {
|
||||||
// if string(stdout) != "active\n" || err != nil {
|
status = constant.Stopped
|
||||||
// status = constant.Stopped
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
|
@ -312,8 +312,7 @@ func (u *SnapshotService) SnapshotRecover(req dto.SnapshotRecover) error {
|
||||||
}
|
}
|
||||||
_ = os.RemoveAll(rootDir)
|
_ = os.RemoveAll(rootDir)
|
||||||
global.LOG.Info("recover successful")
|
global.LOG.Info("recover successful")
|
||||||
_, _ = cmd.Exec("systemctl daemon-reload")
|
_, _ = cmd.Exec("systemctl daemon-reload && systemctl restart 1panel.service")
|
||||||
_, _ = cmd.Exec("systemctl restart 1panel.service")
|
|
||||||
updateRecoverStatus(snap.ID, "", constant.StatusSuccess, "")
|
updateRecoverStatus(snap.ID, "", constant.StatusSuccess, "")
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
|
@ -371,8 +370,7 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if snap.InterruptStep == "UpdateLiveRestore" {
|
if snap.InterruptStep == "UpdateLiveRestore" {
|
||||||
_, _ = cmd.Exec("systemctl daemon-reload")
|
_, _ = cmd.Exec("systemctl restart dockere")
|
||||||
_, _ = cmd.Exec("systemctl restart 1panel.service")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,8 +379,6 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if snap.InterruptStep == "1PanelBinary" {
|
if snap.InterruptStep == "1PanelBinary" {
|
||||||
_, _ = cmd.Exec("systemctl daemon-reload")
|
|
||||||
_, _ = cmd.Exec("systemctl restart 1panel.service")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,8 +387,6 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if snap.InterruptStep == "1PctlBinary" {
|
if snap.InterruptStep == "1PctlBinary" {
|
||||||
_, _ = cmd.Exec("systemctl daemon-reload")
|
|
||||||
_, _ = cmd.Exec("systemctl restart 1panel.service")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,8 +395,7 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if snap.InterruptStep == "1PanelService" {
|
if snap.InterruptStep == "1PanelService" {
|
||||||
_, _ = cmd.Exec("systemctl daemon-reload")
|
_, _ = cmd.Exec("systemctl daemon-reload && systemctl restart 1panel.service")
|
||||||
_, _ = cmd.Exec("systemctl restart 1panel.service")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,8 +404,7 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if snap.InterruptStep == "1PanelBackups" {
|
if snap.InterruptStep == "1PanelBackups" {
|
||||||
_, _ = cmd.Exec("systemctl daemon-reload")
|
_, _ = cmd.Exec("systemctl daemon-reload && systemctl restart 1panel.service")
|
||||||
_, _ = cmd.Exec("systemctl restart 1panel.service")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,15 +413,13 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if snap.InterruptStep == "1PanelData" {
|
if snap.InterruptStep == "1PanelData" {
|
||||||
_, _ = cmd.Exec("systemctl daemon-reload")
|
_, _ = cmd.Exec("systemctl daemon-reload && systemctl restart 1panel.service")
|
||||||
_, _ = cmd.Exec("systemctl restart 1panel.service")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = os.RemoveAll(rootDir)
|
_ = os.RemoveAll(rootDir)
|
||||||
global.LOG.Info("rollback successful")
|
global.LOG.Info("rollback successful")
|
||||||
_, _ = cmd.Exec("systemctl daemon-reload")
|
_, _ = cmd.Exec("systemctl daemon-reload && systemctl restart 1panel.service")
|
||||||
_, _ = cmd.Exec("systemctl restart 1panel.service")
|
|
||||||
updateRollbackStatus(snap.ID, constant.StatusSuccess, "")
|
updateRollbackStatus(snap.ID, constant.StatusSuccess, "")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -764,7 +754,22 @@ func (u *SnapshotService) updateLiveRestore(enabled bool) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(stdout)
|
return errors.New(stdout)
|
||||||
}
|
}
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
|
ticker := time.NewTicker(3 * time.Second)
|
||||||
|
ctx, cancle := context.WithTimeout(context.Background(), time.Second*30)
|
||||||
|
defer cancle()
|
||||||
|
for range ticker.C {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return errors.New("the docker service cannot be restarted")
|
||||||
|
default:
|
||||||
|
stdout, err := cmd.Exec("systemctl is-active docker")
|
||||||
|
if string(stdout) == "active\n" && err == nil {
|
||||||
|
global.LOG.Info("docker restart with new live-restore successful!")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue