in reply to Re: Test if Daemon::Control daemon is running.
in thread Test if Daemon::Control daemon is running.

Thanks, everyone! First, you are correct that running from another script does work fine; to my embarrassment, in my test I used a relative path with FindBin and was looking in the wrong directory for the pid file. This solution works.

However, in the course of this, I picked through the Daemon::Control code, and I'm a bit underwhelmed. Well, useful is the (undocumented, but callable) pid_running method, which does the actual check, and is used by (e.g.) do_status. But this method's MO seems quite inadequate; its only test is to SIG0 the pid. This means that if your daemon crashed and a new process shows up using the same pid the daemon had, then, e.g., do_stop will blindly kill this process!

There is an optional scan_name parameter which does a bit more checking. It does this by spawning a UNIX shell which runs ps to see if the process matches a regex; this seems rather roundabout and inefficient, as opposed to (say) reading /proc/####/cmdline or lstat'ing /proc/####/exe. Maybe it's more portable?

In any case, it's unsettling that this extra test is not the default, so that running Daemon::Control in the usual way can be unsafe. I'd previously assumed it was much more robust than this. Beware.