Mercurial > prosody-modules
annotate mod_reload_modules/mod_reload_modules.lua @ 2635:4548c3d685b4
mod_storage_appendmap: Successfully return nothing on ENOENT
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 21 Mar 2017 15:56:43 +0100 |
parents | fc08d841a309 |
children | 57eb248f6dd3 |
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 |
502
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
31 end |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
32 |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
33 |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
34 if module.hook_global then |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
35 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
|
36 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
|
37 function module.load() |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
38 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
|
39 end |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
40 function module.unload() |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
41 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
|
42 end |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
43 end |