Software /
code /
prosody
Comparison
plugins/mod_posix.lua @ 1712:45a81d6d8777
Merge waqas with Tobias. Eww.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 18 Aug 2009 13:03:35 +0100 |
parent | 1682:883cf1f516a0 |
parent | 1691:e9b589dae393 |
child | 2073:72784ce0c0e0 |
comparison
equal
deleted
inserted
replaced
1686:232c2bf155c7 | 1712:45a81d6d8777 |
---|---|
15 local signal = select(2, pcall(require, "util.signal")); | 15 local signal = select(2, pcall(require, "util.signal")); |
16 if type(signal) == "string" then | 16 if type(signal) == "string" then |
17 module:log("warn", "Couldn't load signal library, won't respond to SIGTERM"); | 17 module:log("warn", "Couldn't load signal library, won't respond to SIGTERM"); |
18 end | 18 end |
19 | 19 |
20 local config_get = require "core.configmanager".get; | |
21 local logger_set = require "util.logger".setwriter; | 20 local logger_set = require "util.logger".setwriter; |
22 | 21 |
23 local prosody = _G.prosody; | 22 local prosody = _G.prosody; |
24 | 23 |
25 module.host = "*"; -- we're a global module | 24 module.host = "*"; -- we're a global module |
26 | 25 |
27 -- Allow switching away from root, some people like strange ports. | 26 -- Allow switching away from root, some people like strange ports. |
28 module:add_event_hook("server-started", function () | 27 module:add_event_hook("server-started", function () |
29 local uid = config_get("*", "core", "setuid"); | 28 local uid = module:get_option("setuid"); |
30 local gid = config_get("*", "core", "setgid"); | 29 local gid = module:get_option("setgid"); |
31 if gid then | 30 if gid then |
32 local success, msg = pposix.setgid(gid); | 31 local success, msg = pposix.setgid(gid); |
33 if success then | 32 if success then |
34 module:log("debug", "Changed group to "..gid.." successfully."); | 33 module:log("debug", "Changed group to "..gid.." successfully."); |
35 else | 34 else |
48 end | 47 end |
49 end); | 48 end); |
50 | 49 |
51 -- Don't even think about it! | 50 -- Don't even think about it! |
52 module:add_event_hook("server-starting", function () | 51 module:add_event_hook("server-starting", function () |
53 local suid = config_get("*", "core", "setuid"); | 52 local suid = module:get_option("setuid"); |
54 if not suid or suid == 0 or suid == "root" then | 53 if not suid or suid == 0 or suid == "root" then |
55 if pposix.getuid() == 0 and not config_get("*", "core", "run_as_root") then | 54 if pposix.getuid() == 0 and not module:get_option("run_as_root") then |
56 module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!"); | 55 module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!"); |
57 module:log("error", "For more information on running Prosody as root, see http://prosody.im/doc/root"); | 56 module:log("error", "For more information on running Prosody as root, see http://prosody.im/doc/root"); |
58 prosody.shutdown("Refusing to run as root"); | 57 prosody.shutdown("Refusing to run as root"); |
59 end | 58 end |
60 end | 59 end |
71 | 70 |
72 local function write_pidfile() | 71 local function write_pidfile() |
73 if pidfile_written then | 72 if pidfile_written then |
74 remove_pidfile(); | 73 remove_pidfile(); |
75 end | 74 end |
76 local pidfile = config_get("*", "core", "pidfile"); | 75 local pidfile = module:get_option("pidfile"); |
77 if pidfile then | 76 if pidfile then |
78 local pf, err = io.open(pidfile, "w+"); | 77 local pf, err = io.open(pidfile, "w+"); |
79 if not pf then | 78 if not pf then |
80 module:log("error", "Couldn't write pidfile; %s", err); | 79 module:log("error", "Couldn't write pidfile; %s", err); |
81 else | 80 else |
101 end | 100 end |
102 end; | 101 end; |
103 end | 102 end |
104 require "core.loggingmanager".register_sink_type("syslog", syslog_sink_maker); | 103 require "core.loggingmanager".register_sink_type("syslog", syslog_sink_maker); |
105 | 104 |
106 if not config_get("*", "core", "no_daemonize") then | 105 if not module:get_option("no_daemonize") then |
107 local function daemonize_server() | 106 local function daemonize_server() |
108 local ok, ret = pposix.daemonize(); | 107 local ok, ret = pposix.daemonize(); |
109 if not ok then | 108 if not ok then |
110 module:log("error", "Failed to daemonize: %s", ret); | 109 module:log("error", "Failed to daemonize: %s", ret); |
111 elseif ret and ret > 0 then | 110 elseif ret and ret > 0 then |