config: handle SIGHUP (#5459)

This commit is contained in:
Caleb Doxsey 2025-01-31 18:31:47 -07:00 committed by GitHub
parent dc9a6bdb81
commit 2754d20a2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 1 deletions

View file

@ -5,7 +5,9 @@ import (
"fmt"
"io"
"os"
"os/signal"
"sync"
"syscall"
"github.com/google/uuid"
"github.com/rs/zerolog"
@ -145,6 +147,16 @@ func NewFileOrEnvironmentSource(
ch := src.watcher.Bind()
go func() {
for range ch {
log.Ctx(ctx).Info().Msg("config: file updated, reconfiguring...")
src.check(ctx)
}
}()
sch := make(chan os.Signal, 1)
signal.Notify(sch, syscall.SIGHUP)
go func() {
for range sch {
log.Ctx(ctx).Info().Msg("config: received SIGHUP, reloading config")
src.check(ctx)
}
}()
@ -156,7 +168,6 @@ func (src *FileOrEnvironmentSource) check(ctx context.Context) {
ctx = log.WithContext(ctx, func(c zerolog.Context) zerolog.Context {
return c.Str("config_change_id", uuid.New().String())
})
log.Ctx(ctx).Info().Msg("config: file updated, reconfiguring...")
src.mu.Lock()
cfg := src.config
options, err := newOptionsFromConfig(src.configFile)