cmd/ctrld: restoring DNS on darwin before stop

Otherwise, we experiment with ctrld slow start after rebooting, because
the network check continuously report failed status even the network
state is up. Restoring the DNS before stopping, we leave the network
state as default, as long as ctrld starts, the DNS is configured again.
This commit is contained in:
Cuong Manh Le
2023-05-13 12:00:33 +07:00
committed by Cuong Manh Le
parent 21c8b9f8e7
commit d3d08022cc
5 changed files with 31 additions and 1 deletions
+1
View File
@@ -138,6 +138,7 @@ func (p *prog) Stop(s service.Service) error {
mainLog.Error().Err(err).Msg("de-allocate ip failed") mainLog.Error().Err(err).Msg("de-allocate ip failed")
return err return err
} }
p.preStop()
mainLog.Info().Msg("Service stopped") mainLog.Info().Msg("Service stopped")
close(p.stopCh) close(p.stopCh)
return nil return nil
+23
View File
@@ -0,0 +1,23 @@
package main
import (
"github.com/kardianos/service"
)
func (p *prog) preRun() {
if !service.Interactive() {
p.setDNS()
}
}
func setDependencies(svc *service.Config) {}
func setWorkingDirectory(svc *service.Config, dir string) {
svc.WorkingDirectory = dir
}
func (p *prog) preStop() {
if !service.Interactive() {
p.resetDNS()
}
}
+2
View File
@@ -18,3 +18,5 @@ func setDependencies(svc *service.Config) {
} }
func setWorkingDirectory(svc *service.Config, dir string) {} func setWorkingDirectory(svc *service.Config, dir string) {}
func (p *prog) preStop() {}
+2
View File
@@ -22,3 +22,5 @@ func setDependencies(svc *service.Config) {
func setWorkingDirectory(svc *service.Config, dir string) { func setWorkingDirectory(svc *service.Config, dir string) {
svc.WorkingDirectory = dir svc.WorkingDirectory = dir
} }
func (p *prog) preStop() {}
+3 -1
View File
@@ -1,4 +1,4 @@
//go:build !linux && !freebsd //go:build !linux && !freebsd && !darwin
package main package main
@@ -12,3 +12,5 @@ func setWorkingDirectory(svc *service.Config, dir string) {
// WorkingDirectory is not supported on Windows. // WorkingDirectory is not supported on Windows.
svc.WorkingDirectory = dir svc.WorkingDirectory = dir
} }
func (p *prog) preStop() {}