aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/loggingmanager.lua19
-rw-r--r--net/httpserver.lua2
-rw-r--r--plugins/mod_posix.lua16
-rwxr-xr-xprosody22
-rwxr-xr-xprosodyctl28
5 files changed, 75 insertions, 12 deletions
diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua
index 58108a23..aa8f368d 100644
--- a/core/loggingmanager.lua
+++ b/core/loggingmanager.lua
@@ -10,7 +10,7 @@ local os_date, os_getenv = os.date, os.getenv;
local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
local config = require "core.configmanager";
-
+local eventmanager = require "core.eventmanager";
local logger = require "util.logger";
_G.log = logger.init("general");
@@ -190,12 +190,26 @@ do
end
end
+local empty_function = function () end;
function log_sink_types.file(config)
local log = config.filename;
local logfile = io_open(log, "a+");
if not logfile then
- return function () end
+ return empty_function;
end
+ local write, flush = logfile.write, logfile.flush;
+
+ eventmanager.add_event_hook("reopen-log-files", function ()
+ if logfile then
+ logfile:close();
+ end
+ logfile = io_open(log, "a+");
+ if not logfile then
+ write, flush = empty_function, empty_function;
+ else
+ write, flush = logfile.write, logfile.flush;
+ end
+ end);
local timestamps = config.timestamps;
@@ -203,7 +217,6 @@ function log_sink_types.file(config)
timestamps = default_timestamp; -- Default format
end
- local write, format, flush = logfile.write, format, logfile.flush;
return function (name, level, message, ...)
if timestamps then
write(logfile, os_date(timestamps), " ");
diff --git a/net/httpserver.lua b/net/httpserver.lua
index 12328b29..af23a91d 100644
--- a/net/httpserver.lua
+++ b/net/httpserver.lua
@@ -11,7 +11,7 @@ local t_insert, t_concat = table.insert, table.concat;
local s_match, s_gmatch = string.match, string.gmatch;
local tonumber, tostring, pairs = tonumber, tostring, pairs;
-local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%x", c:byte()); end)); end
+local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end
local log = require "util.logger".init("httpserver");
diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua
index e6f17cc1..f8a168f0 100644
--- a/plugins/mod_posix.lua
+++ b/plugins/mod_posix.lua
@@ -86,16 +86,18 @@ end
module:add_event_hook("server-stopped", remove_pidfile);
--- Set signal handler
+-- Set signal handlers
if signal.signal then
signal.signal("SIGTERM", function ()
- module:log("warn", "Received SIGTERM...");
+ module:log("warn", "Received SIGTERM");
_G.unlock_globals();
- if _G.prosody_shutdown then
- _G.prosody_shutdown("Received SIGTERM");
- else
- module:log("warn", "...no prosody_shutdown(), ignoring.");
- end
+ _G.prosody_shutdown("Received SIGTERM");
_G.lock_globals();
end);
+
+ signal.signal("SIGHUP", function ()
+ module:log("info", "Received SIGHUP");
+ _G.prosody_reload_config();
+ _G.prosody_reopen_logfiles();
+ end);
end
diff --git a/prosody b/prosody
index 8b6b8ae6..2febe4d8 100755
--- a/prosody
+++ b/prosody
@@ -114,7 +114,27 @@ end);
----------- End of out-of-place code --------------
--- Global function to initiate prosody shutdown
+-- Function to reload the config file
+function prosody_reload_config()
+ log("info", "Reloading configuration file");
+ eventmanager.fire_event("reloading-config");
+ local ok, level, err = config.load((rawget(_G, "CFG_CONFIGDIR") or ".").."/prosody.cfg.lua");
+ if not ok then
+ if level == "parser" then
+ log("error", "There was an error parsing the configuration file: %s", tostring(err));
+ elseif level == "file" then
+ log("error", "Couldn't read the config file when trying to reload: %s", tostring(err));
+ end
+ end
+end
+
+-- Function to reopen logfiles
+function prosody_reopen_logfiles()
+ log("info", "Re-opening log files");
+ eventmanager.fire_event("reopen-log-files"); -- Handled by appropriate log sinks
+end
+
+-- 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 });
diff --git a/prosodyctl b/prosodyctl
index 7998d033..f451b7ee 100755
--- a/prosodyctl
+++ b/prosodyctl
@@ -61,6 +61,29 @@ do
end
end
+-- Switch away from root and into the prosody user --
+local switched_user, current_uid;
+local ok, pposix = pcall(require, "util.pposix");
+if ok and pposix then
+ current_uid = pposix.getuid();
+ if current_uid == 0 then
+ -- We haz root!
+ local desired_user = config.get("*", "core", "prosody_user") or "prosody";
+ local ok, err = pposix.setuid(desired_user);
+ if ok then
+ -- Yay!
+ switched_user = true;
+ else
+ -- Boo!
+ print("Warning: Couldn't switch to Prosody user '"..tostring(desired_user).."': "..tostring(err));
+ end
+ end
+else
+ print("Error: Unable to load pposix module. Check that Prosody is installed correctly.")
+ print("For more help send the below error to us through http://prosody.im/discuss");
+ print(tostring(pposix))
+end
+
local error_messages = setmetatable({
["invalid-username"] = "The given username is invalid in a Jabber ID";
["invalid-hostname"] = "The given hostname is invalid";
@@ -291,6 +314,11 @@ function commands.status(arg)
return 0;
else
show_message("Prosody is not running");
+ if not switched_user and current_uid ~= 0 then
+ print("\nNote: You will also see this if prosodyctl is not running under the same");
+ print(" user account as Prosody. Try running as root (e.g. with 'sudo' in front) to");
+ print(" gain access to Prosody's real status.");
+ end
return 2
end
return 1;