142 ----------- End of out-of-place code -------------- |
142 ----------- End of out-of-place code -------------- |
143 |
143 |
144 -- Function to reload the config file |
144 -- Function to reload the config file |
145 function prosody.reload_config() |
145 function prosody.reload_config() |
146 log("info", "Reloading configuration file"); |
146 log("info", "Reloading configuration file"); |
147 prosody.events.fire_event("reloading-config", {}); |
147 prosody.events.fire_event("reloading-config"); |
148 local ok, level, err = config.load((rawget(_G, "CFG_CONFIGDIR") or ".").."/prosody.cfg.lua"); |
148 local ok, level, err = config.load((rawget(_G, "CFG_CONFIGDIR") or ".").."/prosody.cfg.lua"); |
149 if not ok then |
149 if not ok then |
150 if level == "parser" then |
150 if level == "parser" then |
151 log("error", "There was an error parsing the configuration file: %s", tostring(err)); |
151 log("error", "There was an error parsing the configuration file: %s", tostring(err)); |
152 elseif level == "file" then |
152 elseif level == "file" then |
157 |
157 |
158 -- Function to reopen logfiles |
158 -- Function to reopen logfiles |
159 function prosody.reopen_logfiles() |
159 function prosody.reopen_logfiles() |
160 log("info", "Re-opening log files"); |
160 log("info", "Re-opening log files"); |
161 eventmanager.fire_event("reopen-log-files"); -- Handled by appropriate log sinks |
161 eventmanager.fire_event("reopen-log-files"); -- Handled by appropriate log sinks |
162 prosody.events.fire_event("reopen-log-files", {}); |
162 prosody.events.fire_event("reopen-log-files"); |
163 end |
163 end |
164 |
164 |
165 -- Function to initiate prosody shutdown |
165 -- Function to initiate prosody shutdown |
166 function prosody.shutdown(reason) |
166 function prosody.shutdown(reason) |
167 log("info", "Shutting down: %s", reason or "unknown reason"); |
167 log("info", "Shutting down: %s", reason or "unknown reason"); |
169 server.setquitting(true); |
169 server.setquitting(true); |
170 end |
170 end |
171 |
171 |
172 -- Signal to modules that we are ready to start |
172 -- Signal to modules that we are ready to start |
173 eventmanager.fire_event("server-starting"); |
173 eventmanager.fire_event("server-starting"); |
174 prosody.events.fire_event("server-starting", {}); |
174 prosody.events.fire_event("server-starting"); |
175 |
175 |
176 -- Load SSL settings from config, and create a ctx table |
176 -- Load SSL settings from config, and create a ctx table |
177 local global_ssl_ctx = ssl and config.get("*", "core", "ssl"); |
177 local global_ssl_ctx = ssl and config.get("*", "core", "ssl"); |
178 if global_ssl_ctx then |
178 if global_ssl_ctx then |
179 local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; }; |
179 local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; }; |
227 |
227 |
228 -- And lock now... |
228 -- And lock now... |
229 prosody.lock_globals(); |
229 prosody.lock_globals(); |
230 |
230 |
231 eventmanager.fire_event("server-started"); |
231 eventmanager.fire_event("server-started"); |
232 prosody.events.fire_event("server-started", {}); |
232 prosody.events.fire_event("server-started"); |
233 |
233 |
234 -- Error handler for errors that make it this far |
234 -- Error handler for errors that make it this far |
235 local function catch_uncaught_error(err) |
235 local function catch_uncaught_error(err) |
236 if err:match("%d*: interrupted!$") then |
236 if err:match("%d*: interrupted!$") then |
237 return "quitting"; |
237 return "quitting"; |
249 while select(2, xpcall(server.loop, catch_uncaught_error)) ~= "quitting" do |
249 while select(2, xpcall(server.loop, catch_uncaught_error)) ~= "quitting" do |
250 socket.sleep(0.2); |
250 socket.sleep(0.2); |
251 end |
251 end |
252 |
252 |
253 log("info", "Shutdown status: Cleaning up"); |
253 log("info", "Shutdown status: Cleaning up"); |
254 prosody.events.fire_event("server-cleanup", {}); |
254 prosody.events.fire_event("server-cleanup"); |
255 |
255 |
256 -- Ok, we're quitting I know, but we |
256 -- Ok, we're quitting I know, but we |
257 -- need to do some tidying before we go :) |
257 -- need to do some tidying before we go :) |
258 server.setquitting(false); |
258 server.setquitting(false); |
259 |
259 |
285 server.closeall(); |
285 server.closeall(); |
286 |
286 |
287 server.setquitting(true); |
287 server.setquitting(true); |
288 |
288 |
289 eventmanager.fire_event("server-stopped"); |
289 eventmanager.fire_event("server-stopped"); |
290 prosody.events.fire_event("server-stopped", {}); |
290 prosody.events.fire_event("server-stopped"); |
291 log("info", "Shutdown status: Complete!"); |
291 log("info", "Shutdown status: Complete!"); |