Software /
code /
prosody
Comparison
plugins/mod_posix.lua @ 1062:f9a1ac50782b
mod_posix: Fix calls to log() (replace with module:log) and make some global accesses explicit
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 23 Apr 2009 21:35:24 +0100 |
parent | 1061:8c5876378c6f |
child | 1066:0cb325970a50 |
child | 1092:b547967d87fc |
comparison
equal
deleted
inserted
replaced
1061:8c5876378c6f | 1062:f9a1ac50782b |
---|---|
4 local pposix = assert(require "util.pposix"); | 4 local pposix = assert(require "util.pposix"); |
5 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 | 5 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 |
6 | 6 |
7 local signal = select(2, pcall(require, "util.signal")); | 7 local signal = select(2, pcall(require, "util.signal")); |
8 if type(signal) == "string" then | 8 if type(signal) == "string" then |
9 log("warn", "Couldn't load signal library, won't respond to SIGTERM"); | 9 module:log("warn", "Couldn't load signal library, won't respond to SIGTERM"); |
10 end | 10 end |
11 | 11 |
12 local config_get = require "core.configmanager".get; | 12 local config_get = require "core.configmanager".get; |
13 local logger_set = require "util.logger".setwriter; | 13 local logger_set = require "util.logger".setwriter; |
14 | 14 |
25 | 25 |
26 local function write_pidfile() | 26 local function write_pidfile() |
27 if pidfile_written then | 27 if pidfile_written then |
28 remove_pidfile(); | 28 remove_pidfile(); |
29 end | 29 end |
30 local pidfile = config.get("*", "core", "pidfile"); | 30 local pidfile = config_get("*", "core", "pidfile"); |
31 if pidfile then | 31 if pidfile then |
32 local pf, err = io.open(pidfile, "w+"); | 32 local pf, err = io.open(pidfile, "w+"); |
33 if not pf then | 33 if not pf then |
34 log("error", "Couldn't write pidfile; %s", err); | 34 module:log("error", "Couldn't write pidfile; %s", err); |
35 else | 35 else |
36 pf:write(tostring(pposix.getpid())); | 36 pf:write(tostring(pposix.getpid())); |
37 pf:close(); | 37 pf:close(); |
38 pidfile_written = pidfile; | 38 pidfile_written = pidfile; |
39 end | 39 end |
59 | 59 |
60 if not config_get("*", "core", "no_daemonize") then | 60 if not config_get("*", "core", "no_daemonize") then |
61 local function daemonize_server() | 61 local function daemonize_server() |
62 local ok, ret = pposix.daemonize(); | 62 local ok, ret = pposix.daemonize(); |
63 if not ok then | 63 if not ok then |
64 log("error", "Failed to daemonize: %s", ret); | 64 module:log("error", "Failed to daemonize: %s", ret); |
65 elseif ret and ret > 0 then | 65 elseif ret and ret > 0 then |
66 os.exit(0); | 66 os.exit(0); |
67 else | 67 else |
68 log("info", "Successfully daemonized to PID %d", pposix.getpid()); | 68 module:log("info", "Successfully daemonized to PID %d", pposix.getpid()); |
69 write_pidfile(); | 69 write_pidfile(); |
70 end | 70 end |
71 end | 71 end |
72 module:add_event_hook("server-starting", daemonize_server); | 72 module:add_event_hook("server-starting", daemonize_server); |
73 else | 73 else |
78 module:add_event_hook("server-stopped", remove_pidfile); | 78 module:add_event_hook("server-stopped", remove_pidfile); |
79 | 79 |
80 -- Set signal handler | 80 -- Set signal handler |
81 if signal.signal then | 81 if signal.signal then |
82 signal.signal("SIGTERM", function () | 82 signal.signal("SIGTERM", function () |
83 log("warn", "Received SIGTERM..."); | 83 module:log("warn", "Received SIGTERM..."); |
84 unlock_globals(); | 84 _G.unlock_globals(); |
85 if prosody_shutdown then | 85 if _G.prosody_shutdown then |
86 prosody_shutdown("Received SIGTERM"); | 86 _G.prosody_shutdown("Received SIGTERM"); |
87 else | 87 else |
88 log("warn", "...no prosody_shutdown(), ignoring."); | 88 module:log("warn", "...no prosody_shutdown(), ignoring."); |
89 end | 89 end |
90 lock_globals(); | 90 _G.lock_globals(); |
91 end); | 91 end); |
92 end | 92 end |