python-daemon PID file

Kamil Wasilewski kamil at lucem.pl
Fri Mar 19 07:48:17 EDT 2010


Hi all,

Im trying to get a daemon up and running but have been tripping on every
stone along the way, this last one however i cant manage to get by.
versions:
Python 2.5.2
python-daemon-1.5.5
Debian Linux 2.6.26-2-686

Some of the problems ive run into:

import daemon
with daemon.DaemonContext():
    do_main_program()

doesnt work on my version of Python 2.5.2 so im using

import daemon
import grp
import pwd

diablo.uid = pwd.getpwnam('nobody').pw_uid
diablo.gid = grp.getgrnam('nogroup').gr_gid

daemon.__enter__()
main()
daemon.__exit__()

Next I had problems with Initd starting the daemon because i forgot to chmod
it to 755.

The final problem is with the PID file and getting a correct PID written.
Initially there was no file being created, so i thought i needed the
--make-pidfile option in start-stop-daemon, but ive since learned that the
daemon should create and edit the file, not s-s-d as it inserts the PID of
the parent process, which is not the correct PID of the final daemon.

So i added to my daemon:

import lockfile
daemon.DaemonContext(pidfile=lockfile.FileLock('/var/run/mydaemon.pid'),)


which didnt start the daemon at all as i created the pid file as root, and
was setting the Daemon to run as nobody,nogroup so it was dieing silently.
Im running it as root for now to see if i can get a correct pid in the pid
file.
However no PID file is created, and if i create one its not populated with a
PID.

In summary: I cant get a PID file created or pupulated with a PID by
python-daemon.
Anyone see something that im doing wrong? ive been sitting on this way too
long. I looked at the python-daemon source and i cant see where the pid is
inserted into the pid file, only where it __enter__'s the lockfile so is
this missing?
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100319/c8c0dd9e/attachment.html>


More information about the Python-list mailing list