|
|
|
@ -201,9 +201,8 @@ func (u *DockerService) UpdateConf(req dto.SettingUpdate) error {
|
|
|
|
|
}
|
|
|
|
|
if len(daemonMap) == 0 {
|
|
|
|
|
_ = os.Remove(constant.DaemonJsonPath)
|
|
|
|
|
stdout, err := cmd.Exec("systemctl restart docker")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.New(string(stdout))
|
|
|
|
|
if err := restartDocker(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -218,9 +217,8 @@ func (u *DockerService) UpdateConf(req dto.SettingUpdate) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stdout, err := cmd.Exec("systemctl restart docker")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.New(string(stdout))
|
|
|
|
|
if err := restartDocker(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -268,9 +266,8 @@ func (u *DockerService) UpdateLogOption(req dto.LogOption) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stdout, err := cmd.Exec("systemctl restart docker")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.New(string(stdout))
|
|
|
|
|
if err := restartDocker(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -312,9 +309,8 @@ func (u *DockerService) UpdateIpv6Option(req dto.Ipv6Option) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stdout, err := cmd.Exec("systemctl restart docker")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.New(string(stdout))
|
|
|
|
|
if err := restartDocker(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -322,9 +318,8 @@ func (u *DockerService) UpdateIpv6Option(req dto.Ipv6Option) error {
|
|
|
|
|
func (u *DockerService) UpdateConfByFile(req dto.DaemonJsonUpdateByFile) error {
|
|
|
|
|
if len(req.File) == 0 {
|
|
|
|
|
_ = os.Remove(constant.DaemonJsonPath)
|
|
|
|
|
stdout, err := cmd.Exec("systemctl restart docker")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.New(string(stdout))
|
|
|
|
|
if err := restartDocker(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -345,9 +340,8 @@ func (u *DockerService) UpdateConfByFile(req dto.DaemonJsonUpdateByFile) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stdout, err := cmd.Exec("systemctl restart docker")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.New(string(stdout))
|
|
|
|
|
if err := restartDocker(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -355,6 +349,10 @@ func (u *DockerService) UpdateConfByFile(req dto.DaemonJsonUpdateByFile) error {
|
|
|
|
|
func (u *DockerService) OperateDocker(req dto.DockerOperation) error {
|
|
|
|
|
service := "docker"
|
|
|
|
|
sudo := cmd.SudoHandleCmd()
|
|
|
|
|
dockerCmd, err := getDockerRestartCommand()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if req.Operation == "stop" {
|
|
|
|
|
isSocketActive, _ := systemctl.IsActive("docker.socket")
|
|
|
|
|
if isSocketActive {
|
|
|
|
@ -371,9 +369,9 @@ func (u *DockerService) OperateDocker(req dto.DockerOperation) error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stdout, err := cmd.Execf("systemctl %s %s ", req.Operation, service)
|
|
|
|
|
stdout, err := cmd.Execf("%s %s %s", dockerCmd, req.Operation, service)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.New(string(stdout))
|
|
|
|
|
return errors.New(stdout)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -434,3 +432,27 @@ func validateDockerConfig() error {
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getDockerRestartCommand() (string, error) {
|
|
|
|
|
stdout, err := cmd.Exec("which docker")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("failed to find docker: %v", err)
|
|
|
|
|
}
|
|
|
|
|
dockerPath := stdout
|
|
|
|
|
if strings.Contains(dockerPath, "snap") {
|
|
|
|
|
return "snap", nil
|
|
|
|
|
}
|
|
|
|
|
return "systemctl", nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func restartDocker() error {
|
|
|
|
|
restartCmd, err := getDockerRestartCommand()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
stdout, err := cmd.Execf("%s restart docker", restartCmd)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to restart Docker: %s", stdout)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|