Mercurial > prosody-modules
annotate mod_reload_modules/mod_reload_modules.lua @ 600:03be4622454f
mod_stanza_counter_http: de-revert to use configmanager instead of module mm for the cleanup function also give it an unique name (mismatch possible "??")
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Thu, 09 Feb 2012 00:52:18 +0000 |
parents | aad0b2df9e6b |
children | 412f62d05a23 |
rev | line source |
---|---|
313
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 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
|
2 |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local function reload_module(name) |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local ok, err = mm.reload(module.host, name); |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 if ok then |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 module:log("debug", "Reloaded %s", name); |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 else |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 module:log("error", "Failed to reload %s: %s", name, err); |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 end |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 end |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 |
502
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
12 function reload_all() |
313
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local modules = module:get_option_array("reload_modules"); |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 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
|
15 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
|
16 return; |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 for _, module in ipairs(modules) do |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 reload_module(module); |
524f22ef2c2b
mod_reload_modules: Module to, erm, reload modules, on SIGHUP/config reload
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
502
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
21 end |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
22 |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
23 |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
24 if module.hook_global then |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
25 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
|
26 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
|
27 function module.load() |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
28 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
|
29 end |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
30 function module.unload() |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
31 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
|
32 end |
aad0b2df9e6b
mod_reload_modules: Use module:hook_global() if available
Matthew Wild <mwild1@gmail.com>
parents:
313
diff
changeset
|
33 end |