@@ -21,7 +21,7 @@ import (
2121type DockerService struct {}
2222
2323type IDockerService interface {
24- UpdateConf (req dto.SettingUpdate ) error
24+ UpdateConf (req dto.SettingUpdate , withRestart bool ) error
2525 UpdateLogOption (req dto.LogOption ) error
2626 UpdateIpv6Option (req dto.Ipv6Option ) error
2727 UpdateConfByFile (info dto.DaemonJsonUpdateByFile ) error
@@ -136,7 +136,7 @@ func (u *DockerService) LoadDockerConf() (*dto.DaemonJsonConf, error) {
136136 return & data , nil
137137}
138138
139- func (u * DockerService ) UpdateConf (req dto.SettingUpdate ) error {
139+ func (u * DockerService ) UpdateConf (req dto.SettingUpdate , withRestart bool ) error {
140140 err := createIfNotExistDaemonJsonFile ()
141141 if err != nil {
142142 return err
@@ -222,25 +222,31 @@ func (u *DockerService) UpdateConf(req dto.SettingUpdate) error {
222222 }
223223 }
224224 if len (daemonMap ) == 0 {
225+ if len (file ) == 0 {
226+ return nil
227+ }
225228 _ = os .Remove (constant .DaemonJsonPath )
226- if err := restartDocker (); err != nil {
227- return err
229+ if withRestart {
230+ return restartDocker ()
228231 }
229232 return nil
230233 }
231234 newJson , err := json .MarshalIndent (daemonMap , "" , "\t " )
232235 if err != nil {
233236 return err
234237 }
238+ if string (newJson ) == string (file ) {
239+ return nil
240+ }
235241 if err := os .WriteFile (constant .DaemonJsonPath , newJson , 0640 ); err != nil {
236242 return err
237243 }
238244 if err := validateDockerConfig (); err != nil {
239245 return err
240246 }
241247
242- if err := restartDocker (); err != nil {
243- return err
248+ if withRestart {
249+ return restartDocker ()
244250 }
245251 return nil
246252}
0 commit comments