On 03/27/2012 05:39 PM, Steve Bertrand wrote:
On 2012-03-27 08:36, Mendor wrote:
Hello,

I'm trying to write some daemon application using Proc::Daemon and
Proc::PID::File modules. But I've encountered that Proc::PID::File
crashes when I'm trying to put lockfile to a non-default location. E.g.
the part of code:

my $pid = Proc::PID::File->new(dir => '/var/run/subdirectory');
if ($pid->running()) {
die "Already running";
}

fails with the message "Attempt to bless into a reference at
/usr/share/perl5/site_perl/Proc/PID/File.pm line 144."

I may use default location, but it limits the ability of the daemon to
be run only by root user. Can you help me?


After reviewing the documentation and the code of the module, you should not be calling running() against the object you created with new().

What is happening is that $pid->running() again calls new(), which tries to create (bless) a new object with itself. The code in the module is not designed to allow this.

From what I can tell, you should be using $pid->alive() as opposed to $pid->running().

Steve


Ok, thank you.

But I still have issues with daemon initiation and correct stopping. Could you please explain what is wrong in the source code below?


my $daemon = Proc::Daemon->new(pid_file => '/var/run/mydaemon/mydaemon.pid',
                               work_dir => '/var/run/mydaemon'
                              );
my $pid = $daemon->Init;

my $procpid = Proc::PID::File->new(dir => '/var/run/daemon', name => 'daemon.pid');
if ($procpid->alive()) {
    die "Already running";
}

while (1) {
    # daemon stuff code
}

say "I'm killed :(";


--
Regards.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to