Daemons don't check if one is already running?

9 views
Skip to first unread message

kigster

unread,
Apr 14, 2008, 8:43:46 PM4/14/08
to simple-daemon
Hey there,

I am using simple-daemon to wrap some background tasks in my Rails
App. Everything works as prescribed, but I discovered that I can run
"start" twice on my daemon, and it just overwrites previous pid file
and starts another copy of the daemon.

This feels too much like either I'm doing something wrong, or it's a
bug / design flaw.... I realize that checking for PID file is tricky
(what if the process died and PID is still there?) but just
overwriting the PID file and starting a new instance of the daemon
does not seem right to me either.

Any suggestions? In my case it's crucial that the daemon never starts
another copy, even if the user executes "start" twice.

Thanks!

Jon Dahl

unread,
Apr 21, 2008, 11:03:56 AM4/21/08
to simple-daemon
Hi kigster. You aren't doing anything wrong - simple-daemon just
doesn't have logic built in to ensure that duplicate daemons aren't
started. At the moment, that logic is just assumed to be handled at a
higher level. For example, I usually use monit to manage the stopping
and starting of my daemon processes. Though this isn't perfect...

That said, I think this would be a great addition to simple-daemon.
Check out Lockfile (http://raa.ruby-lang.org/project/lockfile/) for
one tool that could take care of this for you. And if you get this
working within simple-daemon, send me a patch and I'll add it to the
gem. Otherwise, I'll see about adding it (though I probably won't have
a chance for a few weeks...)

Jon
Reply all
Reply to author
Forward
0 new messages