Changeset

1100:05d209ef9661

Merge with 0.4
author Matthew Wild <mwild1@gmail.com>
date Sun, 03 May 2009 01:11:21 +0100
parents 1088:7cf44a5c0991 (current diff) 1099:127e6ae089f8 (diff)
children 1103:b78b1524eb79
files core/componentmanager.lua net/server.lua plugins/mod_posix.lua
diffstat 10 files changed, 72 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sat May 02 17:03:48 2009 +0100
+++ b/Makefile	Sun May 03 01:11:21 2009 +0100
@@ -12,14 +12,15 @@
 INSTALLEDMODULES = $(PREFIX)/lib/prosody/modules
 INSTALLEDDATA = $(DATADIR)
 
-all: prosody.install prosody.cfg.lua.install
+all: prosody.install prosodyctl.install prosody.cfg.lua.install
 	$(MAKE) -C util-src install
 
-install: prosody.install prosody.cfg.lua.install util/encodings.so util/encodings.so util/pposix.so util/signal.so
+install: prosody.install prosodyctl.install prosody.cfg.lua.install util/encodings.so util/encodings.so util/pposix.so util/signal.so
 	install -d $(BIN) $(CONFIG) $(MODULES) $(SOURCE) $(DATA)
 	install -d $(CONFIG)/certs
 	install -d $(SOURCE)/core $(SOURCE)/net $(SOURCE)/util
 	install ./prosody.install $(BIN)/prosody
+	install ./prosodyctl.install $(BIN)/prosodyctl
 	install -m644 core/* $(SOURCE)/core
 	install -m644 net/* $(SOURCE)/net
 	install -m644 util/* $(SOURCE)/util
@@ -31,6 +32,7 @@
 
 clean:
 	rm -f prosody.install
+	rm -f prosodyctl.install
 	rm -f prosody.cfg.lua.install
 	$(MAKE) clean -C util-src
 
@@ -52,6 +54,12 @@
 		s|^CFG_DATADIR=.*;$$|CFG_DATADIR='$(INSTALLEDDATA)';|; \
 		s|^CFG_PLUGINDIR=.*;$$|CFG_PLUGINDIR='$(INSTALLEDMODULES)/';|;" < prosody > prosody.install
 
+prosodyctl.install: prosodyctl
+	sed "s|^CFG_SOURCEDIR=.*;$$|CFG_SOURCEDIR='$(INSTALLEDSOURCE)';|; \
+		s|^CFG_CONFIGDIR=.*;$$|CFG_CONFIGDIR='$(INSTALLEDCONFIG)';|; \
+		s|^CFG_DATADIR=.*;$$|CFG_DATADIR='$(INSTALLEDDATA)';|; \
+		s|^CFG_PLUGINDIR=.*;$$|CFG_PLUGINDIR='$(INSTALLEDMODULES)/';|;" < prosodyctl > prosodyctl.install
+
 prosody.cfg.lua.install:
 	sed 's|certs/|$(INSTALLEDCONFIG)/certs/|' prosody.cfg.lua.dist > prosody.cfg.lua.install
 
--- a/core/componentmanager.lua	Sat May 02 17:03:48 2009 +0100
+++ b/core/componentmanager.lua	Sun May 03 01:11:21 2009 +0100
@@ -44,7 +44,7 @@
 	end
 end
 
-
+local components_loaded_once;
 function load_enabled_components(config)
 	local defined_hosts = config or configmanager.getconfig();
 		
@@ -56,7 +56,7 @@
 			if not ok then
 				log("error", "Error loading %s component %s: %s", tostring(host_config.core.component_module), tostring(host), tostring(err));
 			else
-				log("info", "Activated %s component: %s", host_config.core.component_module, host);
+				log("debug", "Activated %s component: %s", host_config.core.component_module, host);
 			end
 		end
 	end
--- a/core/hostmanager.lua	Sat May 02 17:03:48 2009 +0100
+++ b/core/hostmanager.lua	Sun May 03 01:11:21 2009 +0100
@@ -9,6 +9,8 @@
 
 module "hostmanager"
 
+local hosts_loaded_once;
+
 local function load_enabled_hosts(config)
 	local defined_hosts = config or configmanager.getconfig();
 	
@@ -18,13 +20,14 @@
 		end
 	end
 	eventmanager.fire_event("hosts-activated", defined_hosts);
+	hosts_loaded_once = true;
 end
 
 eventmanager.add_event_hook("server-starting", load_enabled_hosts);
 
 function activate(host, host_config)
 	hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {} };
-	log("info", "Activated host: %s", host);
+	log((hosts_loaded_once and "info") or "debug", "Activated host: %s", host);
 	eventmanager.fire_event("host-activated", host, host_config);
 end
 
--- a/core/modulemanager.lua	Sat May 02 17:03:48 2009 +0100
+++ b/core/modulemanager.lua	Sun May 03 01:11:21 2009 +0100
@@ -53,6 +53,10 @@
 
 -- Load modules when a host is activated
 function load_modules_for_host(host)
+	if config.get(host, "core", "modules_enable") == false then
+		return; -- Only load for hosts, not components, etc.
+	end
+
 	-- Load modules from global section
 	local modules_enabled = config.get("*", "core", "modules_enabled");
 	local modules_disabled = config.get(host, "core", "modules_disabled");
--- a/net/connlisteners.lua	Sat May 02 17:03:48 2009 +0100
+++ b/net/connlisteners.lua	Sun May 03 01:11:21 2009 +0100
@@ -21,11 +21,11 @@
 
 function register(name, listener)
 	if listeners[name] and listeners[name] ~= listener then
-		log("warn", "Listener %s is already registered, not registering any more", name);
+		log("debug", "Listener %s is already registered, not registering any more", name);
 		return false;
 	end
 	listeners[name] = listener;
-	log("info", "Registered connection listener %s", name);
+	log("debug", "Registered connection listener %s", name);
 	return true;
 end
 
--- a/net/server.lua	Sat May 02 17:03:48 2009 +0100
+++ b/net/server.lua	Sun May 03 01:11:21 2009 +0100
@@ -77,6 +77,7 @@
 local addtimer
 local closeall
 local addserver
+local getserver
 local wrapserver
 local getsettings
 local closesocket
@@ -670,6 +671,10 @@
     return handler
 end
 
+getserver = function ( port )
+	return _server[ port ];
+end
+
 removeserver = function( port )
     local handler = _server[ port ]
     if not handler then
@@ -728,7 +733,7 @@
     return _readtraffic, _sendtraffic, _readlistlen, _sendlistlen, _timerlistlen
 end
 
-local dontstop = true;
+local dontstop = true; -- thinking about tomorrow, ...
 
 setquitting = function (quit)
 	dontstop = not quit;
@@ -844,6 +849,7 @@
     closeall = closeall,
     addtimer = addtimer,
     addserver = addserver,
+    getserver = getserver,
     getsettings = getsettings,
     setquitting = setquitting,
     removeserver = removeserver,
--- a/plugins/mod_posix.lua	Sat May 02 17:03:48 2009 +0100
+++ b/plugins/mod_posix.lua	Sun May 03 01:11:21 2009 +0100
@@ -14,6 +14,15 @@
 
 module.host = "*"; -- we're a global module
 
+-- Don't even think about it!
+module:add_event_hook("server-starting", function ()
+		if pposix.getuid() == 0 and not config_get("*", "core", "run_as_root") then
+			module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!");
+			module:log("error", "For more information on running Prosody as root, see http://prosody.im/doc/root");
+			_G.prosody_shutdown("Refusing to run as root");
+		end
+	end);
+
 local pidfile_written;
 
 local function remove_pidfile()
--- a/prosody	Sat May 02 17:03:48 2009 +0100
+++ b/prosody	Sun May 03 01:11:21 2009 +0100
@@ -114,8 +114,17 @@
 
 ----------- End of out-of-place code --------------
 
+-- Global function to initiate prosody shutdown
+function prosody_shutdown(reason)
+	log("info", "Shutting down: %s", reason or "unknown reason");
+	eventmanager.fire_event("server-stopping", { reason = reason });
+	server.setquitting(true);
+end
+
+-- Signal to modules that we are ready to start
 eventmanager.fire_event("server-starting");
 
+-- Load SSL settings from config, and create a ctx table
 local global_ssl_ctx = ssl and config.get("*", "core", "ssl");
 if global_ssl_ctx then
 	local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
@@ -153,13 +162,6 @@
 	cl.start("console", { interface = config.get("*", "core", "console_interface") or "127.0.0.1" })
 end
 
--- Global function to initiate prosody shutdown
-function prosody_shutdown(reason)
-	log("info", "Shutting down: %s", reason or "unknown reason");
-	eventmanager.fire_event("server-stopping", { reason = reason });
-	server.setquitting(true);
-end
-
 -- Catch global accesses --
 local locked_globals_mt = { __index = function (t, k) error("Attempt to read a non-existent global '"..k.."'", 2); end, __newindex = function (t, k, v) error("Attempt to set a global: "..tostring(k).." = "..tostring(v), 2); end }
 
@@ -202,8 +204,9 @@
 -- need to do some tidying before we go :)
 server.setquitting(false);
 
+log("info", "Shutdown status: Closing all active sessions");
 for hostname, host in pairs(hosts) do
-	log("info", "Shutdown status: Closing client connections for %s", hostname)
+	log("debug", "Shutdown status: Closing client connections for %s", hostname)
 	if host.sessions then
 		for username, user in pairs(host.sessions) do
 			for resource, session in pairs(user.sessions) do
@@ -213,7 +216,7 @@
 		end
 	end
 	
-	log("info", "Shutdown status: Closing outgoing s2s connections from %s", hostname);
+	log("debug", "Shutdown status: Closing outgoing s2s connections from %s", hostname);
 	if host.s2sout then
 		for remotehost, session in pairs(host.s2sout) do
 			if session.close then
--- a/prosodyctl	Sat May 02 17:03:48 2009 +0100
+++ b/prosodyctl	Sun May 03 01:11:21 2009 +0100
@@ -238,7 +238,11 @@
 	return 1;
 end
 
-function commands.start()
+function commands.start(arg)
+	if arg[1] == "--help" then
+		show_usage([[start]], [[Start Prosody]]);
+		return 1;
+	end
 	local ok, ret = prosodyctl.isrunning();
 	if not ok then
 		show_message(error_messages[ret]);
@@ -264,7 +268,12 @@
 	return 1;	
 end
 
-function commands.status()
+function commands.status(arg)
+	if arg[1] == "--help" then
+		show_usage([[status]], [[Reports the running status of Prosody]]);
+		return 1;
+	end
+
 	local ok, ret = prosodyctl.isrunning();
 	if not ok then
 		show_message(error_messages[ret]);
@@ -280,11 +289,19 @@
 		end
 		show_message("Prosody is running with PID %s", ret or "(unknown)");
 		return 0;
+	else
+		show_message("Prosody is not running");
+		return 2
 	end
 	return 1;
 end
 
-function commands.stop()
+function commands.stop(arg)
+	if arg[1] == "--help" then
+		show_usage([[stop]], [[Stop a running Prosody server]]);
+		return 1;
+	end
+
 	if not prosodyctl.isrunning() then
 		show_message("Prosody is not running");
 		return 1;
@@ -293,7 +310,7 @@
 	local ok, ret = prosodyctl.stop();
 	if ok then return 0; end
 
-	show_message(error_messages[ret])	
+	show_message(error_messages[ret]);
 	return 1;
 end
 
--- a/util/datamanager.lua	Sat May 02 17:03:48 2009 +0100
+++ b/util/datamanager.lua	Sun May 03 01:11:21 2009 +0100
@@ -55,7 +55,7 @@
 ------- API -------------
 
 function set_data_path(path)
-	log("info", "Setting data path to: %s", path);
+	log("debug", "Setting data path to: %s", path);
 	data_path = path;
 end
 function set_callback(func)