prosody
changeset 1363 daa51f48736d
parent 1314 c18cf7ccc2de
child 1364 9ffd5bab6439
equal deleted inserted replaced
1362:75c39ac6efa0 1363:daa51f48736d
   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 	eventmanager.fire_event("reloading-config");
   147 	eventmanager.fire_event("reloading-config");
       
   148 	prosody.events.fire_event("reloading-config", {});
   148 	local ok, level, err = config.load((rawget(_G, "CFG_CONFIGDIR") or ".").."/prosody.cfg.lua");
   149 	local ok, level, err = config.load((rawget(_G, "CFG_CONFIGDIR") or ".").."/prosody.cfg.lua");
   149 	if not ok then
   150 	if not ok then
   150 		if level == "parser" then
   151 		if level == "parser" then
   151 			log("error", "There was an error parsing the configuration file: %s", tostring(err));
   152 			log("error", "There was an error parsing the configuration file: %s", tostring(err));
   152 		elseif level == "file" then
   153 		elseif level == "file" then
   157 
   158 
   158 -- Function to reopen logfiles
   159 -- Function to reopen logfiles
   159 function prosody.reopen_logfiles()
   160 function prosody.reopen_logfiles()
   160 	log("info", "Re-opening log files");
   161 	log("info", "Re-opening log files");
   161 	eventmanager.fire_event("reopen-log-files"); -- Handled by appropriate log sinks
   162 	eventmanager.fire_event("reopen-log-files"); -- Handled by appropriate log sinks
       
   163 	prosody.events.fire_event("reopen-log-files", {});
   162 end
   164 end
   163 
   165 
   164 -- Function to initiate prosody shutdown
   166 -- Function to initiate prosody shutdown
   165 function prosody.shutdown(reason)
   167 function prosody.shutdown(reason)
   166 	log("info", "Shutting down: %s", reason or "unknown reason");
   168 	log("info", "Shutting down: %s", reason or "unknown reason");
   167 	eventmanager.fire_event("server-stopping", { reason = reason });
   169 	eventmanager.fire_event("server-stopping", { reason = reason });
       
   170 	prosody.events.fire_event("server-stopping", {});
   168 	server.setquitting(true);
   171 	server.setquitting(true);
   169 end
   172 end
   170 
   173 
   171 -- Signal to modules that we are ready to start
   174 -- Signal to modules that we are ready to start
   172 eventmanager.fire_event("server-starting");
   175 eventmanager.fire_event("server-starting");
       
   176 prosody.events.fire_event("server-starting", {});
   173 
   177 
   174 -- Load SSL settings from config, and create a ctx table
   178 -- Load SSL settings from config, and create a ctx table
   175 local global_ssl_ctx = ssl and config.get("*", "core", "ssl");
   179 local global_ssl_ctx = ssl and config.get("*", "core", "ssl");
   176 if global_ssl_ctx then
   180 if global_ssl_ctx then
   177 	local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
   181 	local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
   225 
   229 
   226 -- And lock now...
   230 -- And lock now...
   227 prosody.lock_globals();
   231 prosody.lock_globals();
   228 
   232 
   229 eventmanager.fire_event("server-started");
   233 eventmanager.fire_event("server-started");
       
   234 prosody.events.fire_event("server-started", {});
   230 
   235 
   231 -- Error handler for errors that make it this far
   236 -- Error handler for errors that make it this far
   232 local function catch_uncaught_error(err)
   237 local function catch_uncaught_error(err)
   233 	if err:match("%d*: interrupted!$") then
   238 	if err:match("%d*: interrupted!$") then
   234 		return "quitting";
   239 		return "quitting";
   239 	if traceback then
   244 	if traceback then
   240 		log("error", "%s", traceback);
   245 		log("error", "%s", traceback);
   241 	end
   246 	end
   242 	
   247 	
   243 	eventmanager.fire_event("very-bad-error", "*", err, traceback);
   248 	eventmanager.fire_event("very-bad-error", "*", err, traceback);
       
   249 	prosody.events.fire_event("very-bad-error", {error = err, traceback = traceback});
   244 end
   250 end
   245 
   251 
   246 while select(2, xpcall(server.loop, catch_uncaught_error)) ~= "quitting" do
   252 while select(2, xpcall(server.loop, catch_uncaught_error)) ~= "quitting" do
   247 	socket.sleep(0.2);
   253 	socket.sleep(0.2);
   248 end
   254 end
   249 
   255 
   250 log("info", "Shutdown status: Cleaning up");
   256 log("info", "Shutdown status: Cleaning up");
   251 eventmanager.fire_event("server-cleanup");
   257 eventmanager.fire_event("server-cleanup");
       
   258 prosody.events.fire_event("server-cleanup", {});
   252 
   259 
   253 -- Ok, we're quitting I know, but we
   260 -- Ok, we're quitting I know, but we
   254 -- need to do some tidying before we go :)
   261 -- need to do some tidying before we go :)
   255 server.setquitting(false);
   262 server.setquitting(false);
   256 
   263 
   282 server.closeall();
   289 server.closeall();
   283 
   290 
   284 server.setquitting(true);
   291 server.setquitting(true);
   285 
   292 
   286 eventmanager.fire_event("server-stopped");
   293 eventmanager.fire_event("server-stopped");
       
   294 prosody.events.fire_event("server-stopped", {});
   287 log("info", "Shutdown status: Complete!");
   295 log("info", "Shutdown status: Complete!");