comparison mod_server_status/mod_server_status.lua @ 601:00590d492a5b

mod_server_status: 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:53:32 +0000
parents fe85e18a06cb
children edb4afb6a227
comparison
equal deleted inserted replaced
600:03be4622454f 601:00590d492a5b
128 end 128 end
129 129
130 -- initialization. 130 -- initialization.
131 -- init http interface 131 -- init http interface
132 132
133 function cleanup() -- handy, recycled from mod_register_json 133 function stats_cleanup() -- handy, recycled from mod_register_json
134 module:log("debug", "Cleaning up handlers and stuff as module is being unloaded.") 134 module:log("debug", "Cleaning up handlers and stuff as module is being unloaded.")
135 for _, options in ipairs(ports) do 135 for _, options in ipairs(ports) do
136 if options.port then 136 if options.port then
137 httpserver.new.http_servers[options.port].handlers[options.path or "server-status"] = nil 137 httpserver.new.http_servers[options.port].handlers[options.path or "server-status"] = nil
138 end 138 end
139 end 139 end
140 140
141 local event = module:get_option_boolen("use_libevent", false) 141 local event = require "core.configmanager".get("*", "core", "use_libevent")
142 142
143 -- if there're no handlers left clean the socket, not sure if it works with server_select 143 -- if there're no handlers left clean the socket, not sure if it works with server_select
144 if not event then 144 if not event then
145 for _, options in ipairs(ports) do 145 for _, options in ipairs(ports) do
146 if options.port and not next(httpserver.new.http_servers[options.port].handlers) then 146 if options.port and not next(httpserver.new.http_servers[options.port].handlers) then
152 else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end 152 else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end
153 end 153 end
154 end 154 end
155 end 155 end
156 156
157 prosody.events.remove_handler("module-unloaded", cleanup) 157 prosody.events.remove_handler("module-unloaded", stats_cleanup)
158 end 158 end
159 159
160 local function setup() 160 local function setup()
161 httpserver.new_from_config(ports, request, { base = "server-status" }) 161 httpserver.new_from_config(ports, request, { base = "server-status" })
162 prosody.events.add_handler("module-unloaded", cleanup) 162 prosody.events.add_handler("module-unloaded", stats_cleanup)
163 end 163 end
164 164
165 if prosody.start_time then 165 if prosody.start_time then
166 setup() 166 setup()
167 else 167 else