Merge with 0.4
authorMatthew Wild <mwild1@gmail.com>
Sun, 3 May 2009 00:11:21 +0000 (01:11 +0100)
committerMatthew Wild <mwild1@gmail.com>
Sun, 3 May 2009 00:11:21 +0000 (01:11 +0100)
Makefile
core/componentmanager.lua
core/hostmanager.lua
core/modulemanager.lua
net/connlisteners.lua
net/server.lua
plugins/mod_posix.lua
prosody
prosodyctl
util/datamanager.lua

index 278d260baa63c4dd1efc97859a3ca3c3e724542b..f030821cb86e2bf945d81cd60a2286a92a5dadc8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,14 +12,15 @@ INSTALLEDCONFIG = $(SYSCONFDIR)
 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 @@ install: prosody.install prosody.cfg.lua.install util/encodings.so util/encoding
 
 clean:
        rm -f prosody.install
+       rm -f prosodyctl.install
        rm -f prosody.cfg.lua.install
        $(MAKE) clean -C util-src
 
@@ -52,6 +54,12 @@ prosody.install: prosody
                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
 
index 8b1cce3af218eeb8d259b94e49db52d7140f798b..d76b78495ad092010e034d75002b6fb50bd3e62d 100644 (file)
@@ -44,7 +44,7 @@ local function default_component_handler(origin, stanza)
        end
 end
 
-
+local components_loaded_once;
 function load_enabled_components(config)
        local defined_hosts = config or configmanager.getconfig();
                
@@ -56,7 +56,7 @@ function load_enabled_components(config)
                        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
index 1fec97999d1dcadb868558726d552bd61efd9737..97c742da5f133df86007bcb7d9fcabe2ff1a5de4 100644 (file)
@@ -9,6 +9,8 @@ local pairs = pairs;
 
 module "hostmanager"
 
+local hosts_loaded_once;
+
 local function load_enabled_hosts(config)
        local defined_hosts = config or configmanager.getconfig();
        
@@ -18,13 +20,14 @@ local function load_enabled_hosts(config)
                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
 
index cc48c2f6776ed58cfa29bbdc9408d770a99b01de..2cba50ac0b1b57e08f76222b9c5dadf218b8642e 100644 (file)
@@ -53,6 +53,10 @@ local NULL = {};
 
 -- 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");
index 48101752ee5441cdeee43de002974e31c4aeb163..7aaee4c06f49d27d0a41fe5120e3ddd69808a871 100644 (file)
@@ -21,11 +21,11 @@ local listeners = {};
 
 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
 
index fd6459e849ec251001cb625b96a1cf0d2d5cbb05..9e42b8ff8006fe2d9b5d7c991b71dae905a4c20e 100644 (file)
@@ -77,6 +77,7 @@ local idfalse
 local addtimer\r
 local closeall\r
 local addserver\r
+local getserver\r
 local wrapserver\r
 local getsettings\r
 local closesocket\r
@@ -670,6 +671,10 @@ addserver = function( listeners, port, addr, pattern, sslctx, maxconnections, st
     return handler\r
 end\r
 \r
+getserver = function ( port )\r
+       return _server[ port ];\r
+end\r
+\r
 removeserver = function( port )\r
     local handler = _server[ port ]\r
     if not handler then\r
@@ -728,7 +733,7 @@ stats = function( )
     return _readtraffic, _sendtraffic, _readlistlen, _sendlistlen, _timerlistlen\r
 end\r
 \r
-local dontstop = true;\r
+local dontstop = true; -- thinking about tomorrow, ...\r
 \r
 setquitting = function (quit)\r
        dontstop = not quit;\r
@@ -844,6 +849,7 @@ return {
     closeall = closeall,\r
     addtimer = addtimer,\r
     addserver = addserver,\r
+    getserver = getserver,\r
     getsettings = getsettings,\r
     setquitting = setquitting,\r
     removeserver = removeserver,\r
index b1c7e01b695953c2a1c4dcb2af99676ebb20a3ec..e6f17cc160315bfa42374d8eefd8116c5736d264 100644 (file)
@@ -14,6 +14,15 @@ local logger_set = require "util.logger".setwriter;
 
 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()
diff --git a/prosody b/prosody
index 9bff11cc44a87d1ade8477e6c2bb18903e633389..8e85847fdba8a38a1d26e32e4bd314a3b3d3751d 100755 (executable)
--- a/prosody
+++ b/prosody
@@ -114,8 +114,17 @@ end);
 
 ----------- 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 @@ if cl.get("console") then
        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 @@ eventmanager.fire_event("server-cleanup");
 -- 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 @@ for hostname, host in pairs(hosts) do
                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
index db607833144ec7e1ce02c6c7aeba8aebc6e748fd..098f7475eb905f9af002d20db28c54fb4c1342bc 100755 (executable)
@@ -238,7 +238,11 @@ function commands.deluser(arg)
        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 @@ function commands.start()
        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 @@ function commands.status()
                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 @@ function commands.stop()
        local ok, ret = prosodyctl.stop();
        if ok then return 0; end
 
-       show_message(error_messages[ret])       
+       show_message(error_messages[ret]);
        return 1;
 end
 
index 614f0c80c5b33d7d4c3e14c3d2fcc45b34d31f5c..41d09f060302acdd9f6625d450916f8391617c07 100644 (file)
@@ -55,7 +55,7 @@ local callback;
 ------- 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)