From 360e88f350d52e112f544100cd408d5d54afd43d Mon Sep 17 00:00:00 2001 From: Unrud Date: Sun, 7 May 2017 21:56:05 +0200 Subject: [PATCH] Write PID file in original process This ensures that the PID is written, when the process exists. --- radicale/__main__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/radicale/__main__.py b/radicale/__main__.py index 35c2361..4cdd6fe 100644 --- a/radicale/__main__.py +++ b/radicale/__main__.py @@ -128,11 +128,13 @@ def daemonize(configuration, logger): configuration.get("server", "pid")) from e pid = os.fork() if pid: + # Write PID + if configuration.get("server", "pid"): + with os.fdopen(pid_fd, "w") as pid_file: + pid_file.write(str(pid)) sys.exit() - # Write PID if configuration.get("server", "pid"): - with os.fdopen(pid_fd, "w") as pid_file: - pid_file.write(str(os.getpid())) + os.close(pid_fd) # Decouple environment os.chdir("/") os.setsid()