From 04aef2f0e44e4ee4bcdb419f6ade282f27b5ddfc Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Thu, 8 Sep 2022 02:35:39 -0500 Subject: [PATCH] Reload the config file on SIGHUP --- bot/bot.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bot/bot.go b/bot/bot.go index 4806927..2bbbb29 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -77,6 +77,7 @@ func (b *Bot) RegisterHandlers() { func Run() error { initConfig() + go reloadConfig() if err := lib.SeedMathRand(); err != nil { log.Warn(err) @@ -150,5 +151,17 @@ func loadConfig() { if viper.GetBool("debug") { log.SetLevel(log.DebugLevel) + } else { + log.SetLevel(log.InfoLevel) + } +} + +func reloadConfig() { + sc := make(chan os.Signal, 1) + signal.Notify(sc, syscall.SIGHUP) + for { + <-sc + + loadConfig() } }