Software /
code /
prosody
Comparison
plugins/mod_posix.lua @ 723:c1e7d280c174
mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 15 Jan 2009 20:59:36 +0000 |
parent | 722:63456c9d0522 |
child | 728:fa45dfb27ee5 |
comparison
equal
deleted
inserted
replaced
722:63456c9d0522 | 723:c1e7d280c174 |
---|---|
40 | 40 |
41 local ok, ret = pposix.daemonize(); | 41 local ok, ret = pposix.daemonize(); |
42 if not ok then | 42 if not ok then |
43 log("error", "Failed to daemonize: %s", ret); | 43 log("error", "Failed to daemonize: %s", ret); |
44 elseif ret and ret > 0 then | 44 elseif ret and ret > 0 then |
45 log("info", "Daemonized to pid %d", ret); | |
46 os.exit(0); | 45 os.exit(0); |
47 else | 46 else |
48 if logwriter then | 47 if logwriter then |
49 local ok, ret = logger_set(logwriter); | 48 local ok, ret = logger_set(logwriter); |
50 if not ok then | 49 if not ok then |
51 log("error", "Couldn't set new log output: %s", ret); | 50 log("error", "Couldn't set new log output: %s", ret); |
52 end | 51 end |
53 end | 52 end |
54 log("info", "Successfully daemonized"); | 53 log("info", "Successfully daemonized to PID %d", pposix.getpid()); |
54 | |
55 local pidfile = config.get("*", "core", "pidfile"); | |
56 if pidfile then | |
57 local pf, err = io.open(pidfile, "w+"); | |
58 if not pf then | |
59 log("error", "Couldn't write pidfile; %s", err); | |
60 else | |
61 pf:write(tostring(pposix.getpid())); | |
62 pf:close(); | |
63 end | |
64 end | |
55 end | 65 end |
56 end | 66 end |
57 module:add_event_hook("server-starting", daemonize_server); | 67 module:add_event_hook("server-starting", daemonize_server); |
58 end | 68 end |