aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-04-22 19:59:58 +0100
committerMatthew Wild <mwild1@gmail.com>2009-04-22 19:59:58 +0100
commitca533fa608318506d14639f02c2665c5a31cdcb4 (patch)
tree9b3acd39215d7d5ade950968f36516aabd4ea72c /plugins
parent5014c0ddac8d71c9dd9b44065da610a9278b3d14 (diff)
downloadprosody-ca533fa608318506d14639f02c2665c5a31cdcb4.tar.gz
prosody-ca533fa608318506d14639f02c2665c5a31cdcb4.zip
mod_posix: Remove pidfile on exit
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_posix.lua17
1 files changed, 16 insertions, 1 deletions
diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua
index 2c56f694..abf93a81 100644
--- a/plugins/mod_posix.lua
+++ b/plugins/mod_posix.lua
@@ -14,7 +14,19 @@ local logger_set = require "util.logger".setwriter;
module.host = "*"; -- we're a global module
+local pidfile_written;
+
+local function remove_pidfile()
+ if pidfile_written then
+ os.remove(pidfile);
+ pidfile_written = nil;
+ end
+end
+
local function write_pidfile()
+ if pidfile_written then
+ remove_pidfile();
+ end
local pidfile = config.get("*", "core", "pidfile");
if pidfile then
local pf, err = io.open(pidfile, "w+");
@@ -23,6 +35,7 @@ local function write_pidfile()
else
pf:write(tostring(pposix.getpid()));
pf:close();
+ pidfile_written = pidfile;
end
end
end
@@ -80,10 +93,12 @@ if not config_get("*", "core", "no_daemonize") then
end
module:add_event_hook("server-starting", daemonize_server);
else
+ -- Not going to daemonize, so write the pid of this process
write_pidfile();
- -- Not going to daemonize, but let's write the pidfile anyway
end
+module:add_event_hook("server-stopped", remove_pidfile);
+
-- Set signal handler
if signal.signal then
signal.signal("SIGTERM", function ()