+ clients: re-read auto-clients from /etc/hosts when SIGHUP is received

This commit is contained in:
Simon Zolin 2020-02-18 14:49:50 +03:00
parent e5db33705d
commit fa2f793ac7
2 changed files with 20 additions and 6 deletions

View File

@ -107,6 +107,12 @@ func (clients *clientsContainer) Init(objects []clientObject, dhcpServer *dhcpd.
}
}
// Reload - reload auto-clients
func (clients *clientsContainer) Reload() {
clients.addFromHostsFile()
clients.addFromSystemARP()
}
type clientObject struct {
Name string `yaml:"name"`
Tags []string `yaml:"tags"`
@ -194,8 +200,7 @@ func (clients *clientsContainer) WriteDiskConfig(objects *[]clientObject) {
func (clients *clientsContainer) periodicUpdate() {
for {
clients.addFromHostsFile()
clients.addFromSystemARP()
clients.Reload()
time.Sleep(clientsUpdatePeriod)
}
}

View File

@ -116,10 +116,19 @@ func Main(version string, channel string, armVer string) {
Context.appSignalChannel = make(chan os.Signal)
signal.Notify(Context.appSignalChannel, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
go func() {
<-Context.appSignalChannel
cleanup()
cleanupAlways()
os.Exit(0)
for {
sig := <-Context.appSignalChannel
log.Info("Received signal '%s'", sig)
switch sig {
case syscall.SIGHUP:
Context.clients.Reload()
default:
cleanup()
cleanupAlways()
os.Exit(0)
}
}
}()
// run the protection