فهرست منبع

explicitly reload config from ssh command (#725)

Jon Rafkind 3 سال پیش
والد
کامیت
c2259f14a7
2فایلهای تغییر یافته به همراه9 افزوده شده و 16 حذف شده
  1. 1 1
      main.go
  2. 8 15
      ssh.go

+ 1 - 1
main.go

@@ -327,7 +327,7 @@ func Main(c *config.C, configTest bool, buildVersion string, logger *logrus.Logg
 	//TODO: check if we _should_ be emitting stats
 	//TODO: check if we _should_ be emitting stats
 	go ifce.emitStats(ctx, c.GetDuration("stats.interval", time.Second*10))
 	go ifce.emitStats(ctx, c.GetDuration("stats.interval", time.Second*10))
 
 
-	attachCommands(l, ssh, hostMap, handshakeManager.pendingHostMap, lightHouse, ifce)
+	attachCommands(l, c, ssh, hostMap, handshakeManager.pendingHostMap, lightHouse, ifce)
 
 
 	// Start DNS server last to allow using the nebula IP as lighthouse.dns.host
 	// Start DNS server last to allow using the nebula IP as lighthouse.dns.host
 	var dnsStart func()
 	var dnsStart func()

+ 8 - 15
ssh.go

@@ -12,7 +12,6 @@ import (
 	"runtime/pprof"
 	"runtime/pprof"
 	"sort"
 	"sort"
 	"strings"
 	"strings"
-	"syscall"
 
 
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
 	"github.com/slackhq/nebula/config"
 	"github.com/slackhq/nebula/config"
@@ -166,7 +165,7 @@ func configSSH(l *logrus.Logger, ssh *sshd.SSHServer, c *config.C) (func(), erro
 	return runner, nil
 	return runner, nil
 }
 }
 
 
-func attachCommands(l *logrus.Logger, ssh *sshd.SSHServer, hostMap *HostMap, pendingHostMap *HostMap, lightHouse *LightHouse, ifce *Interface) {
+func attachCommands(l *logrus.Logger, c *config.C, ssh *sshd.SSHServer, hostMap *HostMap, pendingHostMap *HostMap, lightHouse *LightHouse, ifce *Interface) {
 	ssh.RegisterCommand(&sshd.Command{
 	ssh.RegisterCommand(&sshd.Command{
 		Name:             "list-hostmap",
 		Name:             "list-hostmap",
 		ShortDescription: "List all known previously connected hosts",
 		ShortDescription: "List all known previously connected hosts",
@@ -215,7 +214,9 @@ func attachCommands(l *logrus.Logger, ssh *sshd.SSHServer, hostMap *HostMap, pen
 	ssh.RegisterCommand(&sshd.Command{
 	ssh.RegisterCommand(&sshd.Command{
 		Name:             "reload",
 		Name:             "reload",
 		ShortDescription: "Reloads configuration from disk, same as sending HUP to the process",
 		ShortDescription: "Reloads configuration from disk, same as sending HUP to the process",
-		Callback:         sshReload,
+		Callback: func(fs interface{}, a []string, w sshd.StringWriter) error {
+			return sshReload(c, w)
+		},
 	})
 	})
 
 
 	ssh.RegisterCommand(&sshd.Command{
 	ssh.RegisterCommand(&sshd.Command{
@@ -875,16 +876,8 @@ func sshPrintTunnel(ifce *Interface, fs interface{}, a []string, w sshd.StringWr
 	return enc.Encode(copyHostInfo(hostInfo, ifce.hostMap.preferredRanges))
 	return enc.Encode(copyHostInfo(hostInfo, ifce.hostMap.preferredRanges))
 }
 }
 
 
-func sshReload(fs interface{}, a []string, w sshd.StringWriter) error {
-	p, err := os.FindProcess(os.Getpid())
-	if err != nil {
-		return w.WriteLine(err.Error())
-		//TODO
-	}
-	err = p.Signal(syscall.SIGHUP)
-	if err != nil {
-		return w.WriteLine(err.Error())
-		//TODO
-	}
-	return w.WriteLine("HUP sent")
+func sshReload(c *config.C, w sshd.StringWriter) error {
+	err := w.WriteLine("Reloading config")
+	c.ReloadConfig()
+	return err
 }
 }