Single-instance daemons

Cameron Simpson cs at zip.com.au
Wed Nov 12 23:44:10 CET 2008


On 12Nov2008 14:07, Jeff McNeil <jeff at jmcneil.net> wrote:
| On Nov 12, 4:57 pm, Jeffrey Barish <jeff_bar... at earthlink.net> 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.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

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