Software /
code /
prosody
Annotate
plugins/mod_posix.lua @ 719:b1eb112478b8
net.http: Fix to send query part of URL to server
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 15 Jan 2009 04:08:06 +0000 |
parent | 594:6d9b2da9888f |
child | 722:63456c9d0522 |
rev | line source |
---|---|
587 | 1 |
2 local pposix = assert(require "util.pposix"); | |
3 | |
4 local config_get = require "core.configmanager".get; | |
5 local logger_set = require "util.logger".setwriter; | |
6 | |
7 module.host = "*"; -- we're a global module | |
8 | |
9 if not config_get("*", "core", "no_daemonize") then | |
10 local function daemonize_server() | |
11 local logwriter; | |
12 | |
13 local logfilename = config_get("*", "core", "log"); | |
14 if logfilename then | |
15 local logfile = io.open(logfilename, "a+"); | |
16 if logfile then | |
17 local write, format, flush = logfile.write, string.format, logfile.flush; | |
18 logwriter = function (name, level, message, ...) | |
19 if ... then | |
20 write(logfile, name, "\t", level, "\t", format(message, ...), "\n"); | |
21 else | |
22 write(logfile, name, "\t" , level, "\t", message, "\n"); | |
23 end | |
24 flush(logfile); | |
25 end; | |
26 end | |
27 else | |
28 log("debug", "No logging specified, will continue with default"); | |
29 end | |
30 | |
31 local ok, ret = pposix.daemonize(); | |
32 if not ok then | |
33 log("error", "Failed to daemonize: %s", ret); | |
34 elseif ret and ret > 0 then | |
35 log("info", "Daemonized to pid %d", ret); | |
36 os.exit(0); | |
37 else | |
38 if logwriter then | |
39 local ok, ret = logger_set(logwriter); | |
40 if not ok then | |
41 log("error", "Couldn't set new log output: %s", ret); | |
42 end | |
43 end | |
594
6d9b2da9888f
Small logging adjustment for mod_posix
Matthew Wild <mwild1@gmail.com>
parents:
587
diff
changeset
|
44 log("info", "Successfully daemonized"); |
587 | 45 end |
46 end | |
47 module:add_event_hook("server-starting", daemonize_server); | |
48 end |