Starting a service with service.start(block=True) makes the caller process delete the pid
dralves opened this issue · 4 comments
platform=macos
version=0.5.1
The logic on service.start() seems to rely on the caller process dying really fast, before the daemon calls self.pid_file.acquire(). If this doesn't happen (for instance because the caller does some more work or because block=True) then, when the caller dies and the automated cleanup kicks in, the caller will delete the pid file after the daemon calls self.pid_file.acquire() and the file gets deleted without being recreated.
Thanks for your report, @dralves!
I'm not sure whether I understand you correctly: in particular, which automated cleanup are you referring to? There are only two places in the code where a previously created PID file is removed:
- when
Service.run
has finished. - when
Service.is_running
encounters a PID file but no corresponding process exists. Since the PID file stores the daemon's PID this should not be influenced by the caller process exiting.
PidFile (the one from pypi "pid"), on create(), registers a callback to be executed on process exit (line 185 of https://github.com/trbs/pid/blob/master/pid/__init__.py). This makes both the coordinator process (the one that starts the daemon process) and the daemon process race to delete this file. If the coordinator process dies fast, before the daemon process executes self.pid_file.acquire() (
service/src/service/__init__.py
Line 404 in 5cfe2aa