App-CLI-Plugin-Proc-PID-File
view release on metacpan or search on metacpan
lib/App/CLI/Plugin/Proc/PID/File.pm view on Meta::CPAN
my($self, @args) = @_;
say $self->pf->path;
}
=cut
*Proc::PID::File::path = \&_path;
if ($Proc::PID::File::VERSION < $PROC_PID_FILE_RECOMENDED_VERSION) {
{
no warnings "redefine";
*Proc::PID::File::alive = \&_alive;
*Proc::PID::File::read = \&_read;
*Proc::PID::File::touch = \&_touch;
}
}
=pod
=head1 METHOD
=head2 pf
lib/App/CLI/Plugin/Proc/PID/File.pm view on Meta::CPAN
####################################
# Proc::PID::File extended method
####################################
sub _path {
my $self = shift;
return $self->{path};
}
sub _alive {
my $self = shift;
$self->debug("alive(): for A::C::P::Proc::PID::File compat method");
my $pid = $self->read;
if (defined $pid) {
$self->debug("alive(): $pid");
} else {
$self->debug("alive(): not living my process");
return 0;
}
if ($pid != $$ && kill(0, $pid)) {
return $self->verify($pid) ? 1 : 0;
}
return 0;
}
sub _read {
lib/App/CLI/Plugin/Proc/PID/File.pm view on Meta::CPAN
package MyApp::Plugin::MultiLauncherLock;
use strict;
use feature ":5.10.0";
sub prerun {
my($self, @argv) = @_;
if ($self->pf->alive) {
my $pid = $self->pf->read;
die "already " . $self->argv0 . "[$pid] is running";
}
$self->pf->touch;
$self->maybe::next::method(@argv);
}
1;
2. Load MyApp::Plugin::MultiLauncherLock
lib/App/CLI/Plugin/Proc/PID/File.pm view on Meta::CPAN
my($self, @argv) = @_;
my $set = POSIX::SigSet->new(SIGTERM, SIGINT);
my $act = POSIX::SigAction->new(sub {
my $signal = shift;
die "signal $signal recevied...";
}, $set, SA_RESTART);
my $old_act = POSIX::SigAction->new;
sigaction(SIGTERM, $act, $old_act);
sigaction(SIGINT, $act, $old_act);
if ($self->pf->alive) {
my $pid = $self->pf->read;
kill SIGTERM, $pid;
say "old process " . $self->argv0 . "[$pid] is killed";
}
$self->pf->touch;
$self->maybe::next::method(@argv);
}
1;
( run in 0.978 second using v1.01-cache-2.11-cpan-df04353d9ac )