Reload bot.conf and modules on SIGHUP
This commit is contained in:
parent
5c6e8305ca
commit
f236f879f4
1 changed files with 28 additions and 0 deletions
|
@ -6,6 +6,7 @@ class Module(ModuleManager.BaseModule):
|
|||
self._exited = False
|
||||
signal.signal(signal.SIGINT, self.SIGINT)
|
||||
signal.signal(signal.SIGUSR1, self.SIGUSR1)
|
||||
signal.signal(signal.SIGHUP, self.SIGHUP)
|
||||
|
||||
def SIGINT(self, signum, frame):
|
||||
print()
|
||||
|
@ -30,7 +31,34 @@ class Module(ModuleManager.BaseModule):
|
|||
def SIGUSR1(self, signum, frame):
|
||||
self.bot.trigger(self._reload_config)
|
||||
|
||||
def SIGHUP(self, signum, frame):
|
||||
self.bot.trigger(self._SIGHUP)
|
||||
def _SIGHUP(self):
|
||||
self._reload_config()
|
||||
self._reload_modules()
|
||||
|
||||
def _reload_config(self):
|
||||
self.bot.log.info("Reloading config file", [])
|
||||
self.bot.config.load()
|
||||
self.bot.log.info("Reloaded config file", [])
|
||||
|
||||
def _reload(self, name):
|
||||
self.bot.modules.unload_module(name)
|
||||
self.bot.modules.load_module(self.bot, name)
|
||||
def _reload_modules(self):
|
||||
self.bot.log.info("Reloading modules", [])
|
||||
|
||||
reloaded = []
|
||||
failed = []
|
||||
for name in list(self.bot.modules.modules.keys()):
|
||||
try:
|
||||
self._reload(name)
|
||||
except ModuleManager.ModuleWarning:
|
||||
continue
|
||||
except Exception as e:
|
||||
failed.append(name)
|
||||
continue
|
||||
reloaded.append(name)
|
||||
|
||||
self.bot.log.info("Reloaded %d modules (%d failed)",
|
||||
[len(reloaded), len(failed)])
|
||||
|
|
Loading…
Reference in a new issue