summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-04-02 18:30:06 +0200
committermathieui <mathieui@mathieui.net>2012-04-02 18:30:06 +0200
commit941acdb612061190fec341a78d5741c4ee0374e2 (patch)
treee2c649ba02b05802c38a1a92e3d75b8ed01c399d /src
parent4cf1acd9e4dce57cfeff246c7456a2eb1b818258 (diff)
downloadpoezio-941acdb612061190fec341a78d5741c4ee0374e2.tar.gz
poezio-941acdb612061190fec341a78d5741c4ee0374e2.tar.bz2
poezio-941acdb612061190fec341a78d5741c4ee0374e2.tar.xz
poezio-941acdb612061190fec341a78d5741c4ee0374e2.zip
Fixes #2350 (reloading static resources on SIGHUP)
Diffstat (limited to 'src')
-rw-r--r--src/core.py15
-rw-r--r--src/logger.py13
-rw-r--r--src/poezio.py2
3 files changed, 29 insertions, 1 deletions
diff --git a/src/core.py b/src/core.py
index 79417c92..eb7d9e89 100644
--- a/src/core.py
+++ b/src/core.py
@@ -214,6 +214,21 @@ class Core(object):
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):
plugins = config.get('plugins_autoload', '')
for plugin in plugins.split():
diff --git a/src/logger.py b/src/logger.py
index 4f6768cf..4858e116 100644
--- a/src/logger.py
+++ b/src/logger.py
@@ -31,7 +31,18 @@ class Logger(object):
def __del__(self):
for opened_file in self.fds.values():
- opened_file.close()
+ if opened_file:
+ 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):
"""
diff --git a/src/poezio.py b/src/poezio.py
index 7b55ce96..1823b2ec 100644
--- a/src/poezio.py
+++ b/src/poezio.py
@@ -15,6 +15,7 @@ import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import signal
import logging
+from logger import logger
from config import options
import singleton
@@ -30,6 +31,7 @@ def main():
else:
logging.basicConfig(level=logging.CRITICAL)
cocore = singleton.Singleton(core.Core)
+ signal.signal(signal.SIGHUP, cocore.sighup_handler) # ignore ctrl-c
cocore.start()
if not cocore.xmpp.start(): # Connect to remote server
cocore.on_failed_connection()