diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index ede6a1e02..300926ac7 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -10,8 +10,10 @@ import ( "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/constant" + "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/docker" + "github.com/1Panel-dev/1Panel/backend/utils/systemctl" "github.com/pkg/errors" ) @@ -336,8 +338,15 @@ func (u *DockerService) UpdateConfByFile(req dto.DaemonJsonUpdateByFile) error { func (u *DockerService) OperateDocker(req dto.DockerOperation) error { service := "docker" + sudo := cmd.SudoHandleCmd() if req.Operation == "stop" { - service = "docker.socket" + isSocketActive, _ := systemctl.IsActive("docker.socket") + if isSocketActive { + std, err := cmd.Execf("%s systemctl stop docker.socket", sudo) + if err != nil { + global.LOG.Errorf("handle systemctl stop docker.socket failed, err: %v", std) + } + } } stdout, err := cmd.Execf("systemctl %s %s ", req.Operation, service) if err != nil { diff --git a/backend/app/service/ssh.go b/backend/app/service/ssh.go index 4b062c957..1f511d206 100644 --- a/backend/app/service/ssh.go +++ b/backend/app/service/ssh.go @@ -124,6 +124,16 @@ func (u *SSHService) OperateSSH(operation string) error { if operation == "enable" || operation == "disable" { serviceName += ".service" } + if operation == "stop" { + isSocketActive, _ := systemctl.IsActive(serviceName + ".socket") + if isSocketActive { + std, err := cmd.Execf("%s systemctl stop %s", sudo, serviceName+".socket") + if err != nil { + global.LOG.Errorf("handle systemctl stop %s.socket failed, err: %v", serviceName, std) + } + } + } + stdout, err := cmd.Execf("%s systemctl %s %s", sudo, operation, serviceName) if err != nil { if strings.Contains(stdout, "alias name or linked unit file") {