prosody: Log error message when failing to open ports

Sun, 31 Jan 2010 16:40:47 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 31 Jan 2010 16:40:47 +0000
changeset 2846
f2396d7fb6f4
parent 2845
f76139aa7cd5
child 2847
a34decf98668

prosody: Log error message when failing to open ports

prosody file | annotate | diff | comparison | revisions
--- a/prosody	Sat Jan 30 18:51:07 2010 +0000
+++ b/prosody	Sun Jan 31 16:40:47 2010 +0000
@@ -195,7 +195,7 @@
 				if type(port) ~= "number" then
 					log("error", "Non-numeric "..option.."_ports: "..tostring(port));
 				else
-					cl.start(listener, { 
+					local ok, err = cl.start(listener, {
 						ssl = conntype ~= "tcp" and global_ssl_ctx,
 						port = port,
 						interface = config.get("*", "core", option.."_interface") 
@@ -203,6 +203,24 @@
 							or config.get("*", "core", "interface"),
 						type = conntype
 					});
+					if not ok then
+						local friendly_message = err;
+						if err:match(" in use") then
+							if port == 5222 or port == 5223 or port == 5269 then
+								friendly_message = "check that Prosody or another XMPP server is "
+									.."not already running and using this port";
+							elseif port == 80 or port == 81 then
+								friendly_message = "check that a HTTP server is not already using "
+									.."this port";
+							elseif port == 5280 then
+								friendly_message = "check that Prosody or a BOSH connection manager "
+									.."is not already running";
+							end
+						elseif err:match("permission") then
+							friendly_message = "Prosody does not have sufficient privileges to use this port";
+						end
+						log("error", "Failed to open server port %d, %s", port, friendly_message);
+					end
 				end
 			end
 		end

mercurial