Write PID file in original process

This ensures that the PID is written, when the process exists.
This commit is contained in:
Unrud 2017-05-07 21:56:05 +02:00
parent 6ade44c773
commit 360e88f350

View File

@ -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()