|
|
@ -4,6 +4,7 @@ import ( |
|
|
|
"bufio" |
|
|
|
"bufio" |
|
|
|
"context" |
|
|
|
"context" |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
@ -213,6 +214,9 @@ func (u *DockerService) UpdateConf(req dto.SettingUpdate) error { |
|
|
|
if err := os.WriteFile(constant.DaemonJsonPath, newJson, 0640); err != nil { |
|
|
|
if err := os.WriteFile(constant.DaemonJsonPath, newJson, 0640); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if err := validateDockerConfig(); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stdout, err := cmd.Exec("systemctl restart docker") |
|
|
|
stdout, err := cmd.Exec("systemctl restart docker") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -260,6 +264,10 @@ func (u *DockerService) UpdateLogOption(req dto.LogOption) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := validateDockerConfig(); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stdout, err := cmd.Exec("systemctl restart docker") |
|
|
|
stdout, err := cmd.Exec("systemctl restart docker") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return errors.New(string(stdout)) |
|
|
|
return errors.New(string(stdout)) |
|
|
@ -300,6 +308,10 @@ func (u *DockerService) UpdateIpv6Option(req dto.Ipv6Option) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := validateDockerConfig(); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stdout, err := cmd.Exec("systemctl restart docker") |
|
|
|
stdout, err := cmd.Exec("systemctl restart docker") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return errors.New(string(stdout)) |
|
|
|
return errors.New(string(stdout)) |
|
|
@ -329,6 +341,10 @@ func (u *DockerService) UpdateConfByFile(req dto.DaemonJsonUpdateByFile) error { |
|
|
|
_, _ = write.WriteString(req.File) |
|
|
|
_, _ = write.WriteString(req.File) |
|
|
|
write.Flush() |
|
|
|
write.Flush() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := validateDockerConfig(); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stdout, err := cmd.Exec("systemctl restart docker") |
|
|
|
stdout, err := cmd.Exec("systemctl restart docker") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return errors.New(string(stdout)) |
|
|
|
return errors.New(string(stdout)) |
|
|
@ -348,6 +364,13 @@ func (u *DockerService) OperateDocker(req dto.DockerOperation) error { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if req.Operation == "restart" { |
|
|
|
|
|
|
|
if err := validateDockerConfig(); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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)) |
|
|
@ -403,3 +426,11 @@ func changeLogOption(daemonMap map[string]interface{}, logMaxFile, logMaxSize st |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func validateDockerConfig() error { |
|
|
|
|
|
|
|
stdout, err := cmd.Exec("dockerd --validate") |
|
|
|
|
|
|
|
if err != nil || (stdout != "" && strings.TrimSpace(stdout) != "configuration OK") { |
|
|
|
|
|
|
|
return fmt.Errorf("Docker configuration validation failed, err: %v", stdout) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|