Mercurial > prosody-hg
comparison plugins/mod_console.lua @ 1433:e7bd00e70973
mod_console: Reload/unload a module on a component host if it is loaded there
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 28 Jun 2009 02:46:36 +0100 |
| parents | 947d94e3619f |
| children | efd19cdda6ca |
comparison
equal
deleted
inserted
replaced
| 1432:8a59a694a9c0 | 1433:e7bd00e70973 |
|---|---|
| 160 return true, "Server reloaded"; | 160 return true, "Server reloaded"; |
| 161 end | 161 end |
| 162 | 162 |
| 163 def_env.module = {}; | 163 def_env.module = {}; |
| 164 | 164 |
| 165 local function get_hosts_set(hosts) | 165 local function get_hosts_set(hosts, module) |
| 166 if type(hosts) == "table" then | 166 if type(hosts) == "table" then |
| 167 if hosts[1] then | 167 if hosts[1] then |
| 168 return set.new(hosts); | 168 return set.new(hosts); |
| 169 elseif hosts._items then | 169 elseif hosts._items then |
| 170 return hosts; | 170 return hosts; |
| 171 end | 171 end |
| 172 elseif type(hosts) == "string" then | 172 elseif type(hosts) == "string" then |
| 173 return set.new { hosts }; | 173 return set.new { hosts }; |
| 174 elseif hosts == nil then | 174 elseif hosts == nil then |
| 175 local mm = require "modulemanager"; | |
| 175 return set.new(array.collect(keys(prosody.hosts))) | 176 return set.new(array.collect(keys(prosody.hosts))) |
| 176 / function (host) return prosody.hosts[host].type == "local"; end; | 177 / function (host) return prosody.hosts[host].type == "local" or module and mm.is_loaded(host, module); end; |
| 177 end | 178 end |
| 178 end | 179 end |
| 179 | 180 |
| 180 function def_env.module:load(name, hosts, config) | 181 function def_env.module:load(name, hosts, config) |
| 181 local mm = require "modulemanager"; | 182 local mm = require "modulemanager"; |
| 201 end | 202 end |
| 202 | 203 |
| 203 function def_env.module:unload(name, hosts) | 204 function def_env.module:unload(name, hosts) |
| 204 local mm = require "modulemanager"; | 205 local mm = require "modulemanager"; |
| 205 | 206 |
| 206 hosts = get_hosts_set(hosts); | 207 hosts = get_hosts_set(hosts, name); |
| 207 | 208 |
| 208 -- Unload the module for each host | 209 -- Unload the module for each host |
| 209 local ok, err, count = true, nil, 0; | 210 local ok, err, count = true, nil, 0; |
| 210 for host in hosts do | 211 for host in hosts do |
| 211 if mm.is_loaded(host, name) then | 212 if mm.is_loaded(host, name) then |
| 223 end | 224 end |
| 224 | 225 |
| 225 function def_env.module:reload(name, hosts) | 226 function def_env.module:reload(name, hosts) |
| 226 local mm = require "modulemanager"; | 227 local mm = require "modulemanager"; |
| 227 | 228 |
| 228 hosts = get_hosts_set(hosts); | 229 hosts = get_hosts_set(hosts, name); |
| 229 | 230 |
| 230 -- Reload the module for each host | 231 -- Reload the module for each host |
| 231 local ok, err, count = true, nil, 0; | 232 local ok, err, count = true, nil, 0; |
| 232 for host in hosts do | 233 for host in hosts do |
| 233 if mm.is_loaded(host, name) then | 234 if mm.is_loaded(host, name) then |
