Mercurial > prosody-modules
comparison mod_reload_components/mod_reload_components.lua @ 2391:85d04dd87f14
mod_reload_components: add new module and README file.
| author | Camilo <camilo@camilo.fm> |
|---|---|
| date | Mon, 21 Nov 2016 16:18:32 -0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 2390:28fbe960adcf | 2391:85d04dd87f14 |
|---|---|
| 1 module:set_global(); | |
| 2 | |
| 3 local configmanager = require "core.configmanager"; | |
| 4 local hostmanager = require"core.hostmanager"; | |
| 5 | |
| 6 local function reload_components() | |
| 7 | |
| 8 --- Check if host configuration is a component | |
| 9 --- @param h hostname | |
| 10 local function config_is_component(h) | |
| 11 return h ~= nil and configmanager.get(h, "component_module") ~= nil; -- If a host has a component module defined within it, then it is a component | |
| 12 end; | |
| 13 | |
| 14 --- Check if host / component configuration is active | |
| 15 --- @param h hostname / component name | |
| 16 local function component_is_new(h) | |
| 17 return h ~= "*" and not hosts[h]; -- If a host is not defined in hosts and it is not global, then it is new | |
| 18 end | |
| 19 | |
| 20 --- Search for new components that are not activated | |
| 21 for h, c in pairs(configmanager.getconfig()) do | |
| 22 if config_is_component(h) and component_is_new(h) then | |
| 23 module:log ("debug", "Loading new component %s", h ); | |
| 24 hostmanager.activate(h, c); | |
| 25 end | |
| 26 end | |
| 27 | |
| 28 --- Search for active components that are not enabled in the configmanager anymore | |
| 29 local enabled = {} | |
| 30 for h in pairs(configmanager.getconfig()) do | |
| 31 enabled[h] = true; -- Set true if it is defined in the configuration file | |
| 32 end | |
| 33 for h, c in pairs(hosts) do | |
| 34 if not enabled[h] then -- Deactivate if not present in the configuration file | |
| 35 hostmanager.deactivate(h,c); | |
| 36 end | |
| 37 end | |
| 38 end | |
| 39 | |
| 40 module:hook("config-reloaded", reload_components); |
