Comparison

plugins/mod_admin_shell.lua @ 13562:f77c247258cc

mod_admin_shell: Report when a module is already loaded Hopefully less confusing than "Module loaded onto 0 hosts"
author Kim Alvefur <zash@zash.se>
date Fri, 15 Nov 2024 15:52:37 +0100
parent 13561:d8f7a8a26965
child 13582:67c9fc643873
comparison
equal deleted inserted replaced
13561:d8f7a8a26965 13562:f77c247258cc
629 629
630 describe_command [[module:load(module, host) - Load the specified module on the specified host (or all hosts if none given)]] 630 describe_command [[module:load(module, host) - Load the specified module on the specified host (or all hosts if none given)]]
631 function def_env.module:load(name, hosts) 631 function def_env.module:load(name, hosts)
632 hosts = get_hosts_with_module(hosts); 632 hosts = get_hosts_with_module(hosts);
633 633
634 local already_loaded = set.new();
634 -- Load the module for each host 635 -- Load the module for each host
635 local ok, err, count, mod = true, nil, 0; 636 local ok, err, count, mod = true, nil, 0;
636 for host in hosts do 637 for host in hosts do
637 local configured_modules, component = modulemanager.get_modules_for_host(host); 638 local configured_modules, component = modulemanager.get_modules_for_host(host);
638 639
653 654
654 if not (configured_modules:contains(name) or name == component) then 655 if not (configured_modules:contains(name) or name == component) then
655 self.session.print("Note: Module will not be loaded after restart unless enabled in configuration"); 656 self.session.print("Note: Module will not be loaded after restart unless enabled in configuration");
656 end 657 end
657 end 658 end
659 else
660 already_loaded:add(host);
658 end 661 end
659 end 662 end
660 663
661 if not ok then 664 if not ok then
662 return ok, "Last error: "..tostring(err); 665 return ok, "Last error: "..tostring(err);
666 end
667 if already_loaded == hosts then
668 return ok, "Module already loaded";
663 end 669 end
664 return ok, "Module loaded onto "..count.." host"..(count ~= 1 and "s" or ""); 670 return ok, "Module loaded onto "..count.." host"..(count ~= 1 and "s" or "");
665 end 671 end
666 672
667 describe_command [[module:unload(module, host) - The same, but just unloads the module from memory]] 673 describe_command [[module:unload(module, host) - The same, but just unloads the module from memory]]