开发者

Creating a pid_file while using Proc::Daemon::Init

I've been following the explanation in run a perl script as a daemon. I would like to create the pid_file within the perl script. After going through the documentation I was sure that the following piece of code would do it:

use Proc::Daemon;
Proc::Daemon::Init({ pid_开发者_开发技巧file => "/var/run/theprocess.pid"} );

To make a long story short. Id didn't work. I've also tried with the Proc::Daemon->new() operator and it didn't work either. What could I be missing?


Without knowing any details it's hard to tell, but most likely it's one of 2 things:

  • Either pid_file doesn't support a full path. This is unlikely but possible considering that POD example involves separate work_dir argument and path-less pid_file value:

    my $daemon = Proc::Daemon->new(
         work_dir     => '/working/daemon/directory',
         pid_file     => 'pid.txt',
         exec_command => 'perl /home/my_script.pl',
    );
    

    Based on the current code in the module that's not the case (e.g. the example merely doesn't show a valid usage with full path, but such usage is fine); but it could be a new functionality missing from your older module version. Again, unlikely.

  • Or, the file you're writing to can't be created, either because the directory is missing or due to permissioning issue. If that's the case there should be something on STDERR looking like "*Can not open pid_file xxxx*" . Just as FYI, the file is opened for read-write mode (+>).


Actually the problem was that the debian package that installs Proc::Daemon::Init is for version 0.3 which doesn't have the functionality to create the pid files. I ended up doing something like:

use Proc::Daemon;
use Proc::PID::File;

Proc::Daemon::Init();
if (Proc::PID::File->running()) {
    exit;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜