From c2259f14a7d230464613c46e36cbe82116fa2de8 Mon Sep 17 00:00:00 2001 From: Jon Rafkind Date: Mon, 8 Aug 2022 10:44:09 -0700 Subject: [PATCH] explicitly reload config from ssh command (#725) --- main.go | 2 +- ssh.go | 23 ++++++++--------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index e189dce..71bd233 100644 --- a/main.go +++ b/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 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 var dnsStart func() diff --git a/ssh.go b/ssh.go index 01f83a0..376dd82 100644 --- a/ssh.go +++ b/ssh.go @@ -12,7 +12,6 @@ import ( "runtime/pprof" "sort" "strings" - "syscall" "github.com/sirupsen/logrus" "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 } -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{ Name: "list-hostmap", 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{ Name: "reload", 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{ @@ -875,16 +876,8 @@ func sshPrintTunnel(ifce *Interface, fs interface{}, a []string, w sshd.StringWr 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 }