From d3d08022cc55929e274ba50194e98b870dd5013d Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Fri, 21 Apr 2023 10:28:23 +0700 Subject: [PATCH] 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. --- cmd/ctrld/prog.go | 1 + cmd/ctrld/prog_darwin.go | 23 +++++++++++++++++++++++ cmd/ctrld/prog_freebsd.go | 2 ++ cmd/ctrld/prog_linux.go | 2 ++ cmd/ctrld/prog_others.go | 4 +++- 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 cmd/ctrld/prog_darwin.go diff --git a/cmd/ctrld/prog.go b/cmd/ctrld/prog.go index 7388983..08251ef 100644 --- a/cmd/ctrld/prog.go +++ b/cmd/ctrld/prog.go @@ -138,6 +138,7 @@ func (p *prog) Stop(s service.Service) error { mainLog.Error().Err(err).Msg("de-allocate ip failed") return err } + p.preStop() mainLog.Info().Msg("Service stopped") close(p.stopCh) return nil diff --git a/cmd/ctrld/prog_darwin.go b/cmd/ctrld/prog_darwin.go new file mode 100644 index 0000000..2b82eb5 --- /dev/null +++ b/cmd/ctrld/prog_darwin.go @@ -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() + } +} diff --git a/cmd/ctrld/prog_freebsd.go b/cmd/ctrld/prog_freebsd.go index 63d8179..24a90ba 100644 --- a/cmd/ctrld/prog_freebsd.go +++ b/cmd/ctrld/prog_freebsd.go @@ -18,3 +18,5 @@ func setDependencies(svc *service.Config) { } func setWorkingDirectory(svc *service.Config, dir string) {} + +func (p *prog) preStop() {} diff --git a/cmd/ctrld/prog_linux.go b/cmd/ctrld/prog_linux.go index 4ec9416..5cc5d6f 100644 --- a/cmd/ctrld/prog_linux.go +++ b/cmd/ctrld/prog_linux.go @@ -22,3 +22,5 @@ func setDependencies(svc *service.Config) { func setWorkingDirectory(svc *service.Config, dir string) { svc.WorkingDirectory = dir } + +func (p *prog) preStop() {} diff --git a/cmd/ctrld/prog_others.go b/cmd/ctrld/prog_others.go index d790438..b26c0b6 100644 --- a/cmd/ctrld/prog_others.go +++ b/cmd/ctrld/prog_others.go @@ -1,4 +1,4 @@ -//go:build !linux && !freebsd +//go:build !linux && !freebsd && !darwin package main @@ -12,3 +12,5 @@ func setWorkingDirectory(svc *service.Config, dir string) { // WorkingDirectory is not supported on Windows. svc.WorkingDirectory = dir } + +func (p *prog) preStop() {}