mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-05-27 12:52:27 +02:00
Various improvements and bug fixes
- Watch more events for lease file changes - Improving network up detection by using bootstrap IPv6 along side IPv4 one. - Emitting log to notice user that ctrld is starting. - Using systemd wrapper to provide correct status. - Restoring DNS on stop on Windows.
This commit is contained in:
committed by
Cuong Manh Le
parent
0c096d5f07
commit
4896563e3c
+3
-10
@@ -429,6 +429,7 @@ func initCLI() {
|
||||
{s.Install, false},
|
||||
{s.Start, true},
|
||||
}
|
||||
mainLog.Load().Notice().Msg("Starting service")
|
||||
if doTasks(tasks) {
|
||||
if err := p.router.Install(sc); err != nil {
|
||||
mainLog.Load().Warn().Err(err).Msg("post installation failed, please check system/service log for details error")
|
||||
@@ -450,12 +451,7 @@ func initCLI() {
|
||||
uninstall(p, s)
|
||||
os.Exit(1)
|
||||
}
|
||||
// On Linux, Darwin, Freebsd, ctrld set DNS on startup, because the DNS setting could be
|
||||
// reset after rebooting. On windows, we only need to set once here. See prog.preRun in
|
||||
// prog_*.go file for dedicated code on each platform. (1)
|
||||
if runtime.GOOS == "windows" {
|
||||
p.setDNS()
|
||||
}
|
||||
p.setDNS()
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -524,10 +520,7 @@ func initCLI() {
|
||||
initLogging()
|
||||
if doTasks([]task{{s.Stop, true}}) {
|
||||
p.router.Cleanup()
|
||||
// See comment (1) in startCmd.
|
||||
if runtime.GOOS != "windows" {
|
||||
p.resetDNS()
|
||||
}
|
||||
p.resetDNS()
|
||||
mainLog.Load().Notice().Msg("Service stopped")
|
||||
}
|
||||
},
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
"syscall"
|
||||
@@ -63,6 +64,19 @@ func (p *prog) Start(s service.Service) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *prog) preRun() {
|
||||
if !service.Interactive() {
|
||||
p.setDNS()
|
||||
}
|
||||
if runtime.GOOS == "darwin" {
|
||||
p.onStopped = append(p.onStopped, func() {
|
||||
if !service.Interactive() {
|
||||
p.resetDNS()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (p *prog) run() {
|
||||
// Wait the caller to signal that we can do our logic.
|
||||
<-p.waitCh
|
||||
|
||||
@@ -4,17 +4,6 @@ import (
|
||||
"github.com/kardianos/service"
|
||||
)
|
||||
|
||||
func (p *prog) preRun() {
|
||||
if !service.Interactive() {
|
||||
p.setDNS()
|
||||
}
|
||||
p.onStopped = append(p.onStopped, func() {
|
||||
if !service.Interactive() {
|
||||
p.resetDNS()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func setDependencies(svc *service.Config) {}
|
||||
|
||||
func setWorkingDirectory(svc *service.Config, dir string) {
|
||||
|
||||
@@ -6,12 +6,6 @@ import (
|
||||
"github.com/kardianos/service"
|
||||
)
|
||||
|
||||
func (p *prog) preRun() {
|
||||
if !service.Interactive() {
|
||||
p.setDNS()
|
||||
}
|
||||
}
|
||||
|
||||
func setDependencies(svc *service.Config) {
|
||||
// TODO(cuonglm): remove once https://github.com/kardianos/service/issues/359 fixed.
|
||||
_ = os.MkdirAll("/usr/local/etc/rc.d", 0755)
|
||||
|
||||
@@ -13,12 +13,6 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *prog) preRun() {
|
||||
if !service.Interactive() {
|
||||
p.setDNS()
|
||||
}
|
||||
}
|
||||
|
||||
func setDependencies(svc *service.Config) {
|
||||
svc.Dependencies = []string{
|
||||
"Wants=network-online.target",
|
||||
|
||||
@@ -4,8 +4,6 @@ package main
|
||||
|
||||
import "github.com/kardianos/service"
|
||||
|
||||
func (p *prog) preRun() {}
|
||||
|
||||
func setDependencies(svc *service.Config) {}
|
||||
|
||||
func setWorkingDirectory(svc *service.Config, dir string) {
|
||||
|
||||
@@ -26,6 +26,8 @@ func newService(i service.Interface, c *service.Config) (service.Service, error)
|
||||
return &sysV{s}, nil
|
||||
case s.Platform() == "unix-systemv":
|
||||
return &sysV{s}, nil
|
||||
case s.Platform() == "linux-systemd":
|
||||
return &systemd{s}, nil
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
@@ -105,6 +107,20 @@ func (s *procd) Status() (service.Status, error) {
|
||||
return service.StatusRunning, nil
|
||||
}
|
||||
|
||||
// procd wraps a service.Service, and provide status command to
|
||||
// report the status correctly.
|
||||
type systemd struct {
|
||||
service.Service
|
||||
}
|
||||
|
||||
func (s *systemd) Status() (service.Status, error) {
|
||||
out, _ := exec.Command("systemctl", "status", "ctrld").CombinedOutput()
|
||||
if bytes.Contains(out, []byte("/FAILURE)")) {
|
||||
return service.StatusStopped, nil
|
||||
}
|
||||
return s.Service.Status()
|
||||
}
|
||||
|
||||
type task struct {
|
||||
f func() error
|
||||
abortOnError bool
|
||||
|
||||
Reference in New Issue
Block a user