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-04-21 10:28:23 +07:00
committed by Cuong Manh Le
parent 21c8b9f8e7
commit d3d08022cc
5 changed files with 31 additions and 1 deletions

View File

@@ -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

23
cmd/ctrld/prog_darwin.go Normal file
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()
}
}

View File

@@ -18,3 +18,5 @@ func setDependencies(svc *service.Config) {
}
func setWorkingDirectory(svc *service.Config, dir string) {}
func (p *prog) preStop() {}

View File

@@ -22,3 +22,5 @@ func setDependencies(svc *service.Config) {
func setWorkingDirectory(svc *service.Config, dir string) {
svc.WorkingDirectory = dir
}
func (p *prog) preStop() {}

View File

@@ -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() {}