Fixes #2350 (reloading static resources on SIGHUP)

This commit is contained in:
mathieui 2012-04-02 18:30:06 +02:00
parent 4cf1acd9e4
commit 941acdb612
3 changed files with 29 additions and 1 deletions

View file

@ -214,6 +214,21 @@ class Core(object):
self.pending_invites = {} self.pending_invites = {}
def sighup_handler(self, num, stack):
log.debug("SIGHUP caught, reloading the files…")
# reload all log files
log.debug("Reloading the log files…")
logger.reload_all()
log.debug("Log files reloaded.")
# reload the theme
log.debug("Reloading the theme…")
self.command_theme("")
log.debug("Theme reloaded.")
# reload the config from the disk
log.debug("Reloading the config…")
config.__init__(config.file_name)
log.debug("Config reloaded.")
def autoload_plugins(self): def autoload_plugins(self):
plugins = config.get('plugins_autoload', '') plugins = config.get('plugins_autoload', '')
for plugin in plugins.split(): for plugin in plugins.split():

View file

@ -31,8 +31,19 @@ class Logger(object):
def __del__(self): def __del__(self):
for opened_file in self.fds.values(): for opened_file in self.fds.values():
if opened_file:
opened_file.close() opened_file.close()
def reload_all(self):
"""Close and reload all the file handles (on SIGHUP)"""
for opened_file in self.fds.values():
if opened_file:
opened_file.close()
log.debug('All log file handles closed')
for room in self.fds:
self.fds[room] = self.check_and_create_log_dir(room)
log.debug('Log handle for %s re-created', room)
def check_and_create_log_dir(self, room): def check_and_create_log_dir(self, room):
""" """
Check that the directory where we want to log the messages Check that the directory where we want to log the messages

View file

@ -15,6 +15,7 @@ import os
sys.path.append(os.path.dirname(os.path.abspath(__file__))) sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import signal import signal
import logging import logging
from logger import logger
from config import options from config import options
import singleton import singleton
@ -30,6 +31,7 @@ def main():
else: else:
logging.basicConfig(level=logging.CRITICAL) logging.basicConfig(level=logging.CRITICAL)
cocore = singleton.Singleton(core.Core) cocore = singleton.Singleton(core.Core)
signal.signal(signal.SIGHUP, cocore.sighup_handler) # ignore ctrl-c
cocore.start() cocore.start()
if not cocore.xmpp.start(): # Connect to remote server if not cocore.xmpp.start(): # Connect to remote server
cocore.on_failed_connection() cocore.on_failed_connection()