Changeset

313:524f22ef2c2b

mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
author Matthew Wild <mwild1@gmail.com>
date Sat, 08 Jan 2011 18:16:14 +0000
parents 312:31deafcbf623
children 314:df212e1fa576
files mod_reload_modules/mod_reload_modules.lua
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_reload_modules/mod_reload_modules.lua	Sat Jan 08 18:16:14 2011 +0000
@@ -0,0 +1,21 @@
+local mm = require "core.modulemanager";
+
+local function reload_module(name)
+	local ok, err = mm.reload(module.host, name);
+	if ok then
+		module:log("debug", "Reloaded %s", name);
+	else
+		module:log("error", "Failed to reload %s: %s", name, err);
+	end
+end
+
+prosody.events.add_handler("config-reloaded", function ()
+	local modules = module:get_option_array("reload_modules");
+	if not modules then
+		module:log("warn", "No modules listed in the config to reload - set reload_modules to a list");
+		return;
+	end
+	for _, module in ipairs(modules) do
+		reload_module(module);
+	end
+end);