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,
|
2024-10-22 09:00:41 -04:00
|
|
|
s.auth,
|
2024-11-03 19:11:45 -05:00
|
|
|
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)
|
|
|
|
}
|