plugins/mod_posix.lua

Sat, 15 Aug 2009 12:30:43 +0200

author
Tobias Markmann <tm@ayena.de>
date
Sat, 15 Aug 2009 12:30:43 +0200
changeset 1682
883cf1f516a0
parent 1681
e76e2fb26fca
child 1712
45a81d6d8777
permissions
-rw-r--r--

Shutdown prosody if changing user or group fails.

1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1238
diff changeset
1 -- Prosody IM
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1238
diff changeset
2 -- Copyright (C) 2008-2009 Matthew Wild
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1238
diff changeset
3 -- Copyright (C) 2008-2009 Waqas Hussain
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1238
diff changeset
4 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1238
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1238
diff changeset
6 -- COPYING file in the source package for more information.
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1238
diff changeset
7 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1238
diff changeset
8
728
fa45dfb27ee5 mod_posix: Check version of pposix
Matthew Wild <mwild1@gmail.com>
parents: 723
diff changeset
9
1579
95698f021c5d pposix, mod_posix: Bump pposix version number
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
10 local want_pposix_version = "0.3.1";
587
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local pposix = assert(require "util.pposix");
735
d247d061409a mod_posix: logging fix
Matthew Wild <mwild1@gmail.com>
parents: 734
diff changeset
13 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
587
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
15 local signal = select(2, pcall(require, "util.signal"));
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
16 if type(signal) == "string" then
1062
f9a1ac50782b mod_posix: Fix calls to log() (replace with module:log) and make some global accesses explicit
Matthew Wild <mwild1@gmail.com>
parents: 1061
diff changeset
17 module:log("warn", "Couldn't load signal library, won't respond to SIGTERM");
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
18 end
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
19
587
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local config_get = require "core.configmanager".get;
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 local logger_set = require "util.logger".setwriter;
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22
1238
f4c08caca3e7 mod_posix: Use global prosody object
Matthew Wild <mwild1@gmail.com>
parents: 1119
diff changeset
23 local prosody = _G.prosody;
f4c08caca3e7 mod_posix: Use global prosody object
Matthew Wild <mwild1@gmail.com>
parents: 1119
diff changeset
24
587
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 module.host = "*"; -- we're a global module
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
1680
f3d241915429 Add setuid and setgid support.
Tobias Markmann <tm@ayena.de>
parents: 1579
diff changeset
27 -- Allow switching away from root, some people like strange ports.
f3d241915429 Add setuid and setgid support.
Tobias Markmann <tm@ayena.de>
parents: 1579
diff changeset
28 module:add_event_hook("server-started", function ()
f3d241915429 Add setuid and setgid support.
Tobias Markmann <tm@ayena.de>
parents: 1579
diff changeset
29 local uid = config_get("*", "core", "setuid");
f3d241915429 Add setuid and setgid support.
Tobias Markmann <tm@ayena.de>
parents: 1579
diff changeset
30 local gid = config_get("*", "core", "setgid");
f3d241915429 Add setuid and setgid support.
Tobias Markmann <tm@ayena.de>
parents: 1579
diff changeset
31 if gid then
1682
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
32 local success, msg = pposix.setgid(gid);
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
33 if success then
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
34 module:log("debug", "Changed group to "..gid.." successfully.");
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
35 else
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
36 module:log("error", "Failed to change group to "..gid..". Error: "..msg);
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
37 prosody.shutdown("Failed to change group to "..gid);
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
38 end
1680
f3d241915429 Add setuid and setgid support.
Tobias Markmann <tm@ayena.de>
parents: 1579
diff changeset
39 end
f3d241915429 Add setuid and setgid support.
Tobias Markmann <tm@ayena.de>
parents: 1579
diff changeset
40 if uid then
1682
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
41 local success, msg = pposix.setuid(uid);
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
42 if success then
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
43 module:log("debug", "Changed user to "..uid.." successfully.");
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
44 else
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
45 module:log("error", "Failed to change user to "..uid..". Error: "..msg);
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
46 prosody.shutdown("Failed to change user to "..uid);
883cf1f516a0 Shutdown prosody if changing user or group fails.
Tobias Markmann <tm@ayena.de>
parents: 1681
diff changeset
47 end
1680
f3d241915429 Add setuid and setgid support.
Tobias Markmann <tm@ayena.de>
parents: 1579
diff changeset
48 end
f3d241915429 Add setuid and setgid support.
Tobias Markmann <tm@ayena.de>
parents: 1579
diff changeset
49 end);
f3d241915429 Add setuid and setgid support.
Tobias Markmann <tm@ayena.de>
parents: 1579
diff changeset
50
1092
b547967d87fc mod_posix: Don't let the server run as root without the magic run_as_root in config
Matthew Wild <mwild1@gmail.com>
parents: 1062
diff changeset
51 -- Don't even think about it!
b547967d87fc mod_posix: Don't let the server run as root without the magic run_as_root in config
Matthew Wild <mwild1@gmail.com>
parents: 1062
diff changeset
52 module:add_event_hook("server-starting", function ()
1681
e76e2fb26fca Make mod_posix not complain about root user, if setuid is set to something different as root.
Tobias Markmann <tm@ayena.de>
parents: 1680
diff changeset
53 local suid = config_get("*", "core", "setuid");
e76e2fb26fca Make mod_posix not complain about root user, if setuid is set to something different as root.
Tobias Markmann <tm@ayena.de>
parents: 1680
diff changeset
54 if not suid or suid == 0 or suid == "root" then
e76e2fb26fca Make mod_posix not complain about root user, if setuid is set to something different as root.
Tobias Markmann <tm@ayena.de>
parents: 1680
diff changeset
55 if pposix.getuid() == 0 and not config_get("*", "core", "run_as_root") then
e76e2fb26fca Make mod_posix not complain about root user, if setuid is set to something different as root.
Tobias Markmann <tm@ayena.de>
parents: 1680
diff changeset
56 module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!");
e76e2fb26fca Make mod_posix not complain about root user, if setuid is set to something different as root.
Tobias Markmann <tm@ayena.de>
parents: 1680
diff changeset
57 module:log("error", "For more information on running Prosody as root, see http://prosody.im/doc/root");
e76e2fb26fca Make mod_posix not complain about root user, if setuid is set to something different as root.
Tobias Markmann <tm@ayena.de>
parents: 1680
diff changeset
58 prosody.shutdown("Refusing to run as root");
e76e2fb26fca Make mod_posix not complain about root user, if setuid is set to something different as root.
Tobias Markmann <tm@ayena.de>
parents: 1680
diff changeset
59 end
1092
b547967d87fc mod_posix: Don't let the server run as root without the magic run_as_root in config
Matthew Wild <mwild1@gmail.com>
parents: 1062
diff changeset
60 end
b547967d87fc mod_posix: Don't let the server run as root without the magic run_as_root in config
Matthew Wild <mwild1@gmail.com>
parents: 1062
diff changeset
61 end);
b547967d87fc mod_posix: Don't let the server run as root without the magic run_as_root in config
Matthew Wild <mwild1@gmail.com>
parents: 1062
diff changeset
62
1032
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
63 local pidfile_written;
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
64
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
65 local function remove_pidfile()
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
66 if pidfile_written then
1061
8c5876378c6f mod_posix: Fix for removing the pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 1045
diff changeset
67 os.remove(pidfile_written);
1032
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
68 pidfile_written = nil;
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
69 end
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
70 end
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
71
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
72 local function write_pidfile()
1032
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
73 if pidfile_written then
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
74 remove_pidfile();
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
75 end
1062
f9a1ac50782b mod_posix: Fix calls to log() (replace with module:log) and make some global accesses explicit
Matthew Wild <mwild1@gmail.com>
parents: 1061
diff changeset
76 local pidfile = config_get("*", "core", "pidfile");
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
77 if pidfile then
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
78 local pf, err = io.open(pidfile, "w+");
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
79 if not pf then
1062
f9a1ac50782b mod_posix: Fix calls to log() (replace with module:log) and make some global accesses explicit
Matthew Wild <mwild1@gmail.com>
parents: 1061
diff changeset
80 module:log("error", "Couldn't write pidfile; %s", err);
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
81 else
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
82 pf:write(tostring(pposix.getpid()));
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
83 pf:close();
1032
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
84 pidfile_written = pidfile;
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
85 end
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
86 end
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
87 end
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
88
1033
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
89 local syslog_opened
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
90 function syslog_sink_maker(config)
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
91 if not syslog_opened then
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
92 pposix.syslog_open("prosody");
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
93 syslog_opened = true;
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
94 end
1033
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
95 local syslog, format = pposix.syslog_log, string.format;
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
96 return function (name, level, message, ...)
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
97 if ... then
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
98 syslog(level, format(message, ...));
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
99 else
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
100 syslog(level, message);
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
101 end
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
102 end;
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
103 end
1033
4a9f0d482028 mod_posix: Integrate with loggingmanager, register syslog sink, remove redundant logging code
Matthew Wild <mwild1@gmail.com>
parents: 1032
diff changeset
104 require "core.loggingmanager".register_sink_type("syslog", syslog_sink_maker);
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
105
587
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 if not config_get("*", "core", "no_daemonize") then
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 local function daemonize_server()
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 local ok, ret = pposix.daemonize();
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 if not ok then
1062
f9a1ac50782b mod_posix: Fix calls to log() (replace with module:log) and make some global accesses explicit
Matthew Wild <mwild1@gmail.com>
parents: 1061
diff changeset
110 module:log("error", "Failed to daemonize: %s", ret);
587
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 elseif ret and ret > 0 then
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 os.exit(0);
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 else
1062
f9a1ac50782b mod_posix: Fix calls to log() (replace with module:log) and make some global accesses explicit
Matthew Wild <mwild1@gmail.com>
parents: 1061
diff changeset
114 module:log("info", "Successfully daemonized to PID %d", pposix.getpid());
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
115 write_pidfile();
587
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 end
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 end
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 module:add_event_hook("server-starting", daemonize_server);
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
119 else
1032
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
120 -- Not going to daemonize, so write the pid of this process
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
121 write_pidfile();
587
43f509a1519a Add mod_posix, fixes #5
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 end
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
123
1032
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
124 module:add_event_hook("server-stopped", remove_pidfile);
409f22d0430f mod_posix: Remove pidfile on exit
Matthew Wild <mwild1@gmail.com>
parents: 991
diff changeset
125
1118
239d4362a040 mod_posix: Reload the config and reopen log files on SIGHUP
Matthew Wild <mwild1@gmail.com>
parents: 1092
diff changeset
126 -- Set signal handlers
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
127 if signal.signal then
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
128 signal.signal("SIGTERM", function ()
1118
239d4362a040 mod_posix: Reload the config and reopen log files on SIGHUP
Matthew Wild <mwild1@gmail.com>
parents: 1092
diff changeset
129 module:log("warn", "Received SIGTERM");
1238
f4c08caca3e7 mod_posix: Use global prosody object
Matthew Wild <mwild1@gmail.com>
parents: 1119
diff changeset
130 prosody.unlock_globals();
f4c08caca3e7 mod_posix: Use global prosody object
Matthew Wild <mwild1@gmail.com>
parents: 1119
diff changeset
131 prosody.shutdown("Received SIGTERM");
f4c08caca3e7 mod_posix: Use global prosody object
Matthew Wild <mwild1@gmail.com>
parents: 1119
diff changeset
132 prosody.lock_globals();
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
133 end);
1118
239d4362a040 mod_posix: Reload the config and reopen log files on SIGHUP
Matthew Wild <mwild1@gmail.com>
parents: 1092
diff changeset
134
239d4362a040 mod_posix: Reload the config and reopen log files on SIGHUP
Matthew Wild <mwild1@gmail.com>
parents: 1092
diff changeset
135 signal.signal("SIGHUP", function ()
239d4362a040 mod_posix: Reload the config and reopen log files on SIGHUP
Matthew Wild <mwild1@gmail.com>
parents: 1092
diff changeset
136 module:log("info", "Received SIGHUP");
1238
f4c08caca3e7 mod_posix: Use global prosody object
Matthew Wild <mwild1@gmail.com>
parents: 1119
diff changeset
137 prosody.reload_config();
f4c08caca3e7 mod_posix: Use global prosody object
Matthew Wild <mwild1@gmail.com>
parents: 1119
diff changeset
138 prosody.reopen_logfiles();
1118
239d4362a040 mod_posix: Reload the config and reopen log files on SIGHUP
Matthew Wild <mwild1@gmail.com>
parents: 1092
diff changeset
139 end);
991
cd0d75de8345 mod_posix: Allow logging and pidfile options to take effect without needing to daemonize. Add the ability to catch SIGTERM.
Matthew Wild <mwild1@gmail.com>
parents: 735
diff changeset
140 end

mercurial