stillbox/pkg/server/signals.go

44 lines
656 B
Go
Raw Permalink Normal View History

2024-10-22 08:39:15 -04:00
package server
import (
"os"
"os/signal"
"syscall"
2024-11-03 07:19:03 -05:00
"dynatron.me/x/stillbox/pkg/config"
2024-10-22 08:39:15 -04:00
"github.com/rs/zerolog/log"
)
type hupper interface {
HUP(*config.Config)
}
func (s *Server) huppers() []hupper {
return []hupper{
s.logger,
s.auth,
s.tgs,
2024-10-22 08:39:15 -04:00
}
}
func (s *Server) installHupHandler() {
s.hup = make(chan os.Signal, 1)
go func() {
for sig := range s.hup {
log.Info().Msgf("received %s", sig)
err := s.conf.ReadConfig()
if err != nil {
log.Error().Err(err).Msg("cannot read config")
continue
}
hs := s.huppers()
for _, h := range hs {
h.HUP(s.conf)
}
}
}()
signal.Notify(s.hup, syscall.SIGHUP)
}