Software /
code /
prosody-modules
Changeset
564:0b52d82ea0b3
mod_server_status: added http cleanup code from mod_register_json
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Tue, 17 Jan 2012 01:40:58 +0000 |
parents | 563:cd5581b58fdc |
children | 565:9c2eea631811 |
files | mod_server_status/mod_server_status.lua |
diffstat | 1 files changed, 29 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_server_status/mod_server_status.lua Tue Jan 17 01:31:58 2012 +0000 +++ b/mod_server_status/mod_server_status.lua Tue Jan 17 01:40:58 2012 +0000 @@ -129,8 +129,37 @@ -- initialization. -- init http interface + +function cleanup() -- handy, recycled from mod_register_json + module:log("debug", "Cleaning up handlers and stuff as module is being unloaded.") + for _, options in ipairs(ports) do + if options.port then + httpserver.new.http_servers[options.port].handlers[options.path or "server-status"] = nil + end + end + + local event = require "core.configmanager".get("*", "core", "use_libevent"); + + -- if there're no handlers left clean the socket, not sure if it works with server_select + if not event then + for _, options in ipairs(ports) do + if options.port and not next(httpserver.new.http_servers[options.port].handlers) then + httpserver.new.http_servers[options.port] = nil + if options.interface then + for _, value in ipairs(options.interface) do + if server.getserver(value, options.port) then server.removeserver(value, options.port) end + end + else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end + end + end + end + + prosody.events.remove_handler("module-unloaded", cleanup) +end + local function setup() httpserver.new_from_config(ports, request, { base = "server-status" }) + prosody.events.add_handler("module-unloaded", cleanup) end if prosody.start_time then