--
-local want_pposix_version = "0.3.3";
+local want_pposix_version = "0.3.5";
local pposix = assert(require "util.pposix");
if pposix._VERSION ~= want_pposix_version then module:log("warn", "Unknown version (%s) of binary pposix module, expected %s", tostring(pposix._VERSION), want_pposix_version); end
module:log("warn", "Couldn't load signal library, won't respond to SIGTERM");
end
-local logger_set = require "util.logger".setwriter;
-
local lfs = require "lfs";
local stat = lfs.attributes;
local prosody = _G.prosody;
-module.host = "*"; -- we're a global module
+module:set_global(); -- we're a global module
local umask = module:get_option("umask") or "027";
pposix.umask(umask);
-- Allow switching away from root, some people like strange ports.
-module:add_event_hook("server-started", function ()
+module:hook("server-started", function ()
local uid = module:get_option("setuid");
local gid = module:get_option("setgid");
if gid then
pidfile_handle = nil;
prosody.shutdown("Prosody already running");
else
- pidfile_handle:write(tostring(pposix.getpid()));
- pidfile_handle:flush();
+ pidfile_handle:close();
+ pidfile_handle, err = io.open(pidfile, "w+");
+ if not pidfile_handle then
+ module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err);
+ prosody.shutdown("Couldn't write pidfile");
+ else
+ if lfs.lock(pidfile_handle, "w") then
+ pidfile_handle:write(tostring(pposix.getpid()));
+ pidfile_handle:flush();
+ end
+ end
end
end
end
end
-local syslog_opened
+local syslog_opened;
function syslog_sink_maker(config)
if not syslog_opened then
- pposix.syslog_open("prosody");
+ pposix.syslog_open("prosody", module:get_option_string("syslog_facility"));
syslog_opened = true;
end
local syslog, format = pposix.syslog_log, string.format;
return function (name, level, message, ...)
- if ... then
- syslog(level, format(message, ...));
- else
- syslog(level, message);
- end
- end;
+ if ... then
+ syslog(level, format(message, ...));
+ else
+ syslog(level, message);
+ end
+ end;
end
require "core.loggingmanager".register_sink_type("syslog", syslog_sink_maker);
write_pidfile();
end
-module:add_event_hook("server-stopped", remove_pidfile);
+module:hook("server-stopped", remove_pidfile);
-- Set signal handlers
if signal.signal then