aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2013-02-07 21:14:01 +0100
committerFlorian Zeitz <florob@babelmonkeys.de>2013-02-07 21:14:01 +0100
commit6c313762fa8d135030c228fa528e15b64cd6c2db (patch)
tree862c0fc2c5d8963cc5ef41f303cbcc51e3874153
parent0aef88245bec3a73d8f5f5fc4cc0e28902165578 (diff)
downloadprosody-6c313762fa8d135030c228fa528e15b64cd6c2db.tar.gz
prosody-6c313762fa8d135030c228fa528e15b64cd6c2db.zip
mod_admin_adhoc: Implement global module unloading
-rw-r--r--plugins/mod_admin_adhoc.lua64
1 files changed, 64 insertions, 0 deletions
diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua
index f8132d9a..ed65e434 100644
--- a/plugins/mod_admin_adhoc.lua
+++ b/plugins/mod_admin_adhoc.lua
@@ -714,6 +714,68 @@ function unload_modules_handler(self, data, state)
end
end
+local function globally_unload_module_handler(self, data, state)
+ local layout = dataforms_new {
+ title = "Globally unload module";
+ instructions = "Specify a module to unload on all hosts";
+
+ { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-unload" };
+ { name = "module", type = "list-single", required = true, label = "Module to globally unload:"};
+ };
+ if state then
+ if data.action == "cancel" then
+ return { status = "canceled" };
+ end
+
+ local is_global = false;
+ local fields, err = layout:data(data.form);
+ if err then
+ return generate_error_message(err);
+ end
+
+ if modulemanager.is_loaded("*", fields.module) then
+ local ok, err = modulemanager.unload("*", fields.module);
+ if not ok then
+ return { status = "completed", info = 'Global module '..fields.module..' failed to unload: '..err };
+ end
+ is_global = true;
+ end
+
+ local ok_list, err_list = {}, {};
+ for host_name, host in pairs(hosts) do
+ if modulemanager.is_loaded(host_name, fields.module) then
+ local ok, err = modulemanager.unload(host_name, fields.module);
+ if ok then
+ ok_list[#ok_list + 1] = host_name;
+ else
+ err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")";
+ end
+ end
+ end
+
+ if #ok_list == 0 and #err_list == 0 then
+ if is_global then
+ return { status = "completed", info = 'Successfully unloaded global module '..fields.module };
+ else
+ return { status = "completed", info = 'Module '..fields.module..' not loaded on any host.' };
+ end
+ end
+
+ local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully unloaded on the hosts:\n"..t_concat(ok_list, "\n")) or "")
+ .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
+ (#err_list > 0 and ("Failed to unload the module "..fields.module.." on the hosts:\n"..t_concat(err_list, "\n")) or "");
+ return { status = "completed", info = info };
+ else
+ local loaded_modules = array(keys(modulemanager.get_modules("*")));
+ for _, host in pairs(hosts) do
+ loaded_modules:append(array(keys(host.modules)));
+ end
+ loaded_modules = array(keys(set.new(loaded_modules):items())):sort();
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout, values = { module = loaded_modules } } }, "executing";
+ end
+end
+
+
function activate_host_handler(self, data, state)
local layout = dataforms_new {
title = "Activate host";
@@ -787,6 +849,7 @@ local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/proto
local globally_reload_module_desc = adhoc_new("Globally reload module", "http://prosody.im/protocol/modules#global-reload", globally_reload_module_handler, "global_admin");
local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin");
local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin");
+local globally_unload_module_desc = adhoc_new("Globally unload module", "http://prosody.im/protocol/modules#global-unload", globally_unload_module_handler, "global_admin");
local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin");
local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin");
@@ -806,5 +869,6 @@ module:provides("adhoc", reload_modules_desc);
module:provides("adhoc", globally_reload_module_desc);
module:provides("adhoc", shut_down_service_desc);
module:provides("adhoc", unload_modules_desc);
+module:provides("adhoc", globally_unload_module_desc);
module:provides("adhoc", activate_host_desc);
module:provides("adhoc", deactivate_host_desc);