From c2ca2940ee535bebe10956515344991142c7f498 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 2 May 2009 17:48:28 +0100 Subject: prosodyctl: Multiple fixes for start/status/stop --- prosodyctl | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/prosodyctl b/prosodyctl index db607833..098f7475 100755 --- a/prosodyctl +++ b/prosodyctl @@ -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 -- cgit v1.2.3 From 3163adb138ae8b1e1e4144a567e4619dcef7893c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 2 May 2009 20:30:50 +0100 Subject: Makefile: Process and install prosodyctl --- Makefile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 278d260b..f030821c 100644 --- 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 -- cgit v1.2.3 From cdefe721448365b25bf3217bbbdd25c04b3a7091 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 2 May 2009 20:32:17 +0100 Subject: prosody: Define prosody_shutdown() before emitting the server-starting event --- prosody | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/prosody b/prosody index 9bff11cc..b0bc579b 100755 --- 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 } -- cgit v1.2.3 From a073502b279b5127895f4953702bed54bcc7dbfb Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 2 May 2009 20:32:43 +0100 Subject: mod_posix: Don't let the server run as root without the magic run_as_root in config --- plugins/mod_posix.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua index b1c7e01b..e6f17cc1 100644 --- a/plugins/mod_posix.lua +++ b/plugins/mod_posix.lua @@ -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() -- cgit v1.2.3 From d3d75a69835b26e31f3e20eb94159b491d02358c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 2 May 2009 20:36:20 +0100 Subject: prosody: Less verbose logging during shutdown sequence --- prosody | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/prosody b/prosody index b0bc579b..8e85847f 100755 --- a/prosody +++ b/prosody @@ -204,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 @@ -215,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 -- cgit v1.2.3 From dda93565feb7be092cbb2b22b29f5c667da94344 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 2 May 2009 22:01:22 +0100 Subject: modulemanager: Don't load modules when modules_enable is false --- core/modulemanager.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/modulemanager.lua b/core/modulemanager.lua index cc48c2f6..2cba50ac 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -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"); -- cgit v1.2.3 From de88c377e19b89a90af943305dd8905851fa3f77 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 2 May 2009 22:02:43 +0100 Subject: hostmanager: Reduce log output at startup to 'debug' --- core/hostmanager.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/hostmanager.lua b/core/hostmanager.lua index 1fec9799..97c742da 100644 --- a/core/hostmanager.lua +++ b/core/hostmanager.lua @@ -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 -- cgit v1.2.3 From f28e5c887cc99f30a0b290ced40f7b5ab8c236ba Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 2 May 2009 22:03:44 +0100 Subject: componentmanager: Reduce log output at startup to 'debug' --- core/componentmanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/componentmanager.lua b/core/componentmanager.lua index 524d334b..93e2ae7b 100644 --- a/core/componentmanager.lua +++ b/core/componentmanager.lua @@ -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 -- cgit v1.2.3 From 6026cb4616067aedb88070e2ba85fca05aeba341 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 2 May 2009 22:04:21 +0100 Subject: util.datamanager: Lower log level of 'Setting data path' to 'debug' --- util/datamanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/datamanager.lua b/util/datamanager.lua index 614f0c80..41d09f06 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -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) -- cgit v1.2.3 From c017eb23257e4ea60fb654ffe96aee963e048722 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 3 May 2009 01:09:57 +0100 Subject: net.server: Add getserver() method to find the server listening on the specified port --- net/server.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/server.lua b/net/server.lua index 77bc2f5c..b2b19c70 100644 --- a/net/server.lua +++ b/net/server.lua @@ -77,6 +77,7 @@ local idfalse local addtimer local closeall local addserver +local getserver local wrapserver local getsettings local closesocket @@ -670,6 +671,10 @@ addserver = function( listeners, port, addr, pattern, sslctx, maxconnections, st 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 @@ stats = function( ) 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 @@ return { closeall = closeall, addtimer = addtimer, addserver = addserver, + getserver = getserver, getsettings = getsettings, setquitting = setquitting, removeserver = removeserver, -- cgit v1.2.3 From 7be3d9f227ff8083e396497507dbdfe9a6049ca8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 3 May 2009 01:10:49 +0100 Subject: net.connlisteners: Lower log level of multiple listeners warning (not interesting to end-users) --- net/connlisteners.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/connlisteners.lua b/net/connlisteners.lua index 48101752..7aaee4c0 100644 --- a/net/connlisteners.lua +++ b/net/connlisteners.lua @@ -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 -- cgit v1.2.3