Mercurial > prosody-modules
annotate mod_reload_modules/mod_reload_modules.lua @ 3877:562b34050561
mod_rest: Add basic support for XEP-0050: Ad-Hoc commands (no forms)
This allows calling simple commands like the one provided by mod_uptime
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 04 Feb 2020 21:49:14 +0100 |
parents | 57eb248f6dd3 |
children | 3b8f4f3b1718 |
rev | line source |
---|---|
1178
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
1 local array, it, set = require "util.array", require "util.iterators", require "util.set"; |
313
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local mm = require "core.modulemanager"; |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
502
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
4 function reload_all() |
1178
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
5 local modules = module:get_option_set("reload_modules", {}); |
313
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 if not modules then |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 module:log("warn", "No modules listed in the config to reload - set reload_modules to a list"); |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 return; |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 end |
1178
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
10 local configured_modules = module:get_option_inherited_set("modules_enabled", {}); |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
11 local loaded_modules = set.new(array.collect(it.keys(prosody.hosts[module.host].modules))); |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
12 local need_to_load = set.intersection(configured_modules - loaded_modules, modules); |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
13 local need_to_unload = set.intersection(loaded_modules - configured_modules, modules); |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
14 |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
15 for module_name in need_to_load do |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
16 module:log("debug", "Loading %s", module_name); |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
17 mm.load(module.host, module_name); |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
18 end |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
19 |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
20 for module_name in need_to_unload do |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
21 module:log("debug", "Unloading %s", module_name); |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
22 mm.unload(module.host, module_name); |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
23 end |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
24 |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
25 modules:exclude(need_to_load+need_to_unload) |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
26 |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
27 for module_name in set.intersection(modules,configured_modules) do |
412f62d05a23
mod_reload_modules: Add support for loading/unloading of modules, as well as simply reloading
Matthew Wild <mwild1@gmail.com>
parents:
502
diff
changeset
|
28 module:log("debug", "Reloading %s", module_name); |
1644
fc08d841a309
mod_reload_modules: Fix a bug introduced in commit 412f62d05a23, which caused mod_reload_modules to... not reload modules
Matthew Wild <mwild1@gmail.com>
parents:
1178
diff
changeset
|
29 mm.reload(module.host, module_name); |
313
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 end |
3759
57eb248f6dd3
mod_reload_modules: Accept a list of global modules to reload
Matthew Wild <mwild1@gmail.com>
parents:
1644
diff
changeset
|
31 |
57eb248f6dd3
mod_reload_modules: Accept a list of global modules to reload
Matthew Wild <mwild1@gmail.com>
parents:
1644
diff
changeset
|
32 local global_modules = module:get_option_set("reload_global_modules", {}); |
57eb248f6dd3
mod_reload_modules: Accept a list of global modules to reload
Matthew Wild <mwild1@gmail.com>
parents:
1644
diff
changeset
|
33 for module_name in global_modules do |
57eb248f6dd3
mod_reload_modules: Accept a list of global modules to reload
Matthew Wild <mwild1@gmail.com>
parents:
1644
diff
changeset
|
34 module:log("debug", "Global reload of mod_%s", module_name); |
57eb248f6dd3
mod_reload_modules: Accept a list of global modules to reload
Matthew Wild <mwild1@gmail.com>
parents:
1644
diff
changeset
|
35 mm.reload("*", module_name); |
57eb248f6dd3
mod_reload_modules: Accept a list of global modules to reload
Matthew Wild <mwild1@gmail.com>
parents:
1644
diff
changeset
|
36 end |
502
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
37 end |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
38 |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
39 |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
40 if module.hook_global then |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
41 module:hook_global("config-reloaded", reload_all); |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
42 else -- COMPAT w/pre-0.9 |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
43 function module.load() |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
44 prosody.events.add_handler("config-reloaded", reload_all); |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
45 end |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
46 function module.unload() |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
47 prosody.events.remove_handler("config-reloaded", reload_all); |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
48 end |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
49 end |