Single-instance daemons

Cameron Simpson cs at
Wed Nov 12 23:44:10 CET 2008

On 12Nov2008 14:07, Jeff McNeil <jeff at> wrote:
| On Nov 12, 4:57 pm, Jeffrey Barish <jeff_bar... at> wrote:
| > As per Stevens/Rago, "file and record locking provides a convenient
| > mutual-exclusion mechanism".  They note the convention of putting the lock
| > file in /var/run in a file called <name>.pid, where <name> is the name of
| > the daemon and content is the pid.  Seems like a good suggestion as I see
| > pid files from many other daemons there.  However, /var/run is owned by
| > root, so it is not possible to write in it without root permission.[...]
| Sure, start the daemon as root, write the appropriate files, and then
| drop permissions using os.setegid and then os.seteuid. [...]

Or, more simply, get root to make an empty pid file once and chown it to
the daemon user. Then the daemon can rewrite the file as needed. You need
to move to truncating the file instead of removing it on daemon shutdown,
but that is trivial. And no mucking with privileges, like starting the
daemon as root instead of directly as the daemon user, need be done.

Cameron Simpson <cs at> DoD#743

They said it couldn't be done/they said nobody could do it/
But he tried the thing that couldn't be done!/He tried - and he couldn't do it.

More information about the Python-list mailing list