Python daemon no pidfile

Hello, I am writing a daemon in python that uses the python-daemon module, my application starts up correctly, the pidfile.lock file is created, but there is no pidfile sign containing the process identifier.

import daemon import lockfile import perfagentmain context = daemon.DaemonContext( working_directory='/opt/lib/perf-agent', umask=0o002, pidfile=lockfile.FileLock('/var/run/perf-agent.pid') ) with context: perfagentmain.start() 
+4
source share
1 answer

I agree with @npoektop's comment about the solution. I would say that daemon.pidlockfile does not exist at the time I am writing this. daemon.pidfile . Maybe the last name has changed?

So, instead, here's a general solution using the daemon.pidfile module instead of the lockfile module.

 import daemon import daemon.pidfile import perfagentmain context = daemon.DaemonContext( working_directory='/opt/lib/perf-agent', umask=0o002, pidfile=daemon.pidfile.PIDLockFile('/var/run/perf-agent.pid') ) with context: perfagentmain.start() 

And @Martino Dino, you are absolutely right, it seems that the lockfile module has a completely different implementation of writing lock files. (although python-daemon does require a lockfile )

When I tried pidfile = lockfile.FileLock('/var/run/mydaemon.pid') for my own needs, instead I saw a file named <MY_MACHINE_NAME>-<8CHAR_HEX_ID>.<PID_OFF_BY_2> , as well as the file /var/run/mydaemon.pid.lock . This answer mentions how this method of hardlinking a randomly named file to your pidlock file was a file locking method before using O_EXCL , used when opening files.

But the annoying part was that the file did not contain a PID, as you said, and the file name had a PID that was turned off by several valid PID numbers, so it was terribly wrong.

+4
source

Source: https://habr.com/ru/post/1493936/


All Articles