Reload the config file on SIGHUP

This commit is contained in:
Ryan Cavicchioni 2022-09-08 02:35:39 -05:00
parent 9221a218b9
commit 04aef2f0e4
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D

View File

@ -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()
}
}