order of operations when daemonizing

Ethan Furman ethan at stoneleaf.us
Tue May 20 21:49:33 UTC 2014


On 05/20/2014 09:58 AM, Ethan Furman wrote:
>
> I suggest that the detach happen after all the prep work is complete, which solves most of the above issues.

Well, of course that took more work than just moving a couple lines up.  ;)

I had to break the acquire/write_pid into two steps:

   acquire:  open the file, but leave it empty -- any errors
             with this part will still go the terminal; also
             change the owner of the file to match the final
             uid/gid

   seal:     after detach and pid change, write the new pid
             and close the file

I ended up writing the pid files into /var/tmp since they cannot be deleted from /var/run by the non-privileged user 
that my daemon ends up running as.

--
~Ethan~



More information about the python-daemon-devel mailing list