Software / code / prosody
Comparison
plugins/mod_admin_shell.lua @ 13128:38582771b593
mod_admin_shell: Warn when (un-)loading module would be undone by restart
Reminder to update the configuration if the change is to be permanent.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 06 Jun 2023 22:00:54 +0200 |
| parent | 13117:7eb6244b4984 |
| child | 13132:5bfcfd12c423 |
comparison
equal
deleted
inserted
replaced
| 13127:f45a29b32f7a | 13128:38582771b593 |
|---|---|
| 597 hosts = get_hosts_with_module(hosts); | 597 hosts = get_hosts_with_module(hosts); |
| 598 | 598 |
| 599 -- Load the module for each host | 599 -- Load the module for each host |
| 600 local ok, err, count, mod = true, nil, 0; | 600 local ok, err, count, mod = true, nil, 0; |
| 601 for host in hosts do | 601 for host in hosts do |
| 602 local configured_modules, component = modulemanager.get_modules_for_host(host); | |
| 603 | |
| 602 if (not modulemanager.is_loaded(host, name)) then | 604 if (not modulemanager.is_loaded(host, name)) then |
| 603 mod, err = modulemanager.load(host, name); | 605 mod, err = modulemanager.load(host, name); |
| 604 if not mod then | 606 if not mod then |
| 605 ok = false; | 607 ok = false; |
| 606 if err == "global-module-already-loaded" then | 608 if err == "global-module-already-loaded" then |
| 611 end | 613 end |
| 612 self.session.print(err or "Unknown error loading module"); | 614 self.session.print(err or "Unknown error loading module"); |
| 613 else | 615 else |
| 614 count = count + 1; | 616 count = count + 1; |
| 615 self.session.print("Loaded for "..mod.module.host); | 617 self.session.print("Loaded for "..mod.module.host); |
| 618 | |
| 619 if not (configured_modules:contains(name) or name == component) then | |
| 620 self.session.print("Note: Module will not be loaded after restart unless enabled in configuration"); | |
| 621 end | |
| 616 end | 622 end |
| 617 end | 623 end |
| 618 end | 624 end |
| 619 | 625 |
| 620 return ok, (ok and "Module loaded onto "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); | 626 return ok, (ok and "Module loaded onto "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); |
| 624 hosts = get_hosts_with_module(hosts, name); | 630 hosts = get_hosts_with_module(hosts, name); |
| 625 | 631 |
| 626 -- Unload the module for each host | 632 -- Unload the module for each host |
| 627 local ok, err, count = true, nil, 0; | 633 local ok, err, count = true, nil, 0; |
| 628 for host in hosts do | 634 for host in hosts do |
| 635 local configured_modules, component = modulemanager.get_modules_for_host(host); | |
| 636 | |
| 629 if modulemanager.is_loaded(host, name) then | 637 if modulemanager.is_loaded(host, name) then |
| 630 ok, err = modulemanager.unload(host, name); | 638 ok, err = modulemanager.unload(host, name); |
| 631 if not ok then | 639 if not ok then |
| 632 ok = false; | 640 ok = false; |
| 633 self.session.print(err or "Unknown error unloading module"); | 641 self.session.print(err or "Unknown error unloading module"); |
| 634 else | 642 else |
| 635 count = count + 1; | 643 count = count + 1; |
| 636 self.session.print("Unloaded from "..host); | 644 self.session.print("Unloaded from "..host); |
| 645 | |
| 646 if configured_modules:contains(name) or name == component then | |
| 647 self.session.print("Note: Module will be loaded after restart unless disabled in configuration"); | |
| 648 end | |
| 637 end | 649 end |
| 638 end | 650 end |
| 639 end | 651 end |
| 640 return ok, (ok and "Module unloaded from "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); | 652 return ok, (ok and "Module unloaded from "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); |
| 641 end | 653 end |