Comparison

plugins/mod_admin_adhoc.lua @ 5327:b0c36b043f00

mod_admin_adhoc: Implement global module reloading
author Florian Zeitz <florob@babelmonkeys.de>
date Thu, 07 Feb 2013 00:40:00 +0100
parent 5326:e96361eb8286
child 5328:5e15e6700412
comparison
equal deleted inserted replaced
5326:e96361eb8286 5327:b0c36b043f00
552 local modules = array.collect(keys(hosts[data.to].modules)):sort(); 552 local modules = array.collect(keys(hosts[data.to].modules)):sort();
553 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout; values = { modules = modules } } }, "executing"; 553 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout; values = { modules = modules } } }, "executing";
554 end 554 end
555 end 555 end
556 556
557 local function globally_reload_module_handler(self, data, state)
558 local layout = dataforms_new {
559 title = "Globally reload module";
560 instructions = "Specify the module to reload on all hosts";
561
562 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-reload" };
563 { name = "module", type = "list-single", required = true, label = "Module to globally reload:"};
564 };
565 if state then
566 if data.action == "cancel" then
567 return { status = "canceled" };
568 end
569
570 local is_global = false;
571 local fields, err = layout:data(data.form);
572 if err then
573 return generate_error_message(err);
574 end
575
576 if modulemanager.is_loaded("*", fields.module) then
577 local ok, err = modulemanager.reload("*", fields.module);
578 if not ok then
579 return { status = "completed", info = 'Global module '..fields.module..' failed to reload: '..err };
580 end
581 is_global = true;
582 end
583
584 local ok_list, err_list = {}, {};
585 for host_name, host in pairs(hosts) do
586 if modulemanager.is_loaded(host_name, fields.module) then
587 local ok, err = modulemanager.reload(host_name, fields.module);
588 if ok then
589 ok_list[#ok_list + 1] = host_name;
590 else
591 err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")";
592 end
593 end
594 end
595
596 if #ok_list == 0 and #err_list == 0 then
597 if is_global then
598 return { status = "completed", info = 'Successfully reloaded global module '..fields.module };
599 else
600 return { status = "completed", info = 'Module '..fields.module..' not loaded on any host.' };
601 end
602 end
603
604 local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully reloaded on the hosts:\n"..t_concat(ok_list, "\n")) or "")
605 .. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
606 (#err_list > 0 and ("Failed to reload the module "..fields.module.." on the hosts:\n"..t_concat(err_list, "\n")) or "");
607 return { status = "completed", info = info };
608 else
609 local loaded_modules = array(keys(modulemanager.get_modules("*")));
610 for _, host in pairs(hosts) do
611 loaded_modules:append(array(keys(host.modules)));
612 end
613 loaded_modules = array(keys(set.new(loaded_modules):items())):sort();
614 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = { layout = layout, values = { module = loaded_modules } } }, "executing";
615 end
616 end
617
557 function send_to_online(message, server) 618 function send_to_online(message, server)
558 if server then 619 if server then
559 sessions = { [server] = hosts[server] }; 620 sessions = { [server] = hosts[server] };
560 else 621 else
561 sessions = hosts; 622 sessions = hosts;
721 local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users", get_online_users_command_handler, "admin"); 782 local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users", get_online_users_command_handler, "admin");
722 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); 783 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin");
723 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin"); 784 local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin");
724 local globally_load_module_desc = adhoc_new("Globally load module", "http://prosody.im/protocol/modules#global-load", globally_load_module_handler, "global_admin"); 785 local globally_load_module_desc = adhoc_new("Globally load module", "http://prosody.im/protocol/modules#global-load", globally_load_module_handler, "global_admin");
725 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin"); 786 local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin");
787 local globally_reload_module_desc = adhoc_new("Globally reload module", "http://prosody.im/protocol/modules#global-reload", globally_reload_module_handler, "global_admin");
726 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin"); 788 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin");
727 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); 789 local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin");
728 local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin"); 790 local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin");
729 local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin"); 791 local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin");
730 792
739 module:provides("adhoc", get_online_users_desc); 801 module:provides("adhoc", get_online_users_desc);
740 module:provides("adhoc", list_modules_desc); 802 module:provides("adhoc", list_modules_desc);
741 module:provides("adhoc", load_module_desc); 803 module:provides("adhoc", load_module_desc);
742 module:provides("adhoc", globally_load_module_desc); 804 module:provides("adhoc", globally_load_module_desc);
743 module:provides("adhoc", reload_modules_desc); 805 module:provides("adhoc", reload_modules_desc);
806 module:provides("adhoc", globally_reload_module_desc);
744 module:provides("adhoc", shut_down_service_desc); 807 module:provides("adhoc", shut_down_service_desc);
745 module:provides("adhoc", unload_modules_desc); 808 module:provides("adhoc", unload_modules_desc);
746 module:provides("adhoc", activate_host_desc); 809 module:provides("adhoc", activate_host_desc);
747 module:provides("adhoc", deactivate_host_desc); 810 module:provides("adhoc", deactivate_host_desc);