| 1 | package XAS::Lib::Pidfile::Unix; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $VERSION = '0.02'; | |||||||||
| 4 | |||||||||||
| 5 | use XAS::Class | ||||||||||
| 6 | 1 | debug => 0, | |||||||||
| 7 | version => $VERSION, | ||||||||||
| 8 | base => 'XAS::Base', | ||||||||||
| 9 | mixins => 'is_running scan_name', | ||||||||||
| 10 | utils => 'run_cmd trim compress', | ||||||||||
| 11 | 1 | ▶ | ; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | # ---------------------------------------------------------------------- | ||||||||||
| 14 | # Public Methods | ||||||||||
| 15 | # ---------------------------------------------------------------------- | ||||||||||
| 16 | |||||||||||
| 17 | sub scan_name { | ||||||||||
| 18 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
scan_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 19 | |||||||||||
| 20 | # just return the name of the script | ||||||||||
| 21 | |||||||||||
| 22 | 0 | my $c = sprintf('%s', $self->env->script); | |||||||||
| 23 | |||||||||||
| 24 | 0 | return compress($c); | |||||||||
| 25 | |||||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | sub is_running { | ||||||||||
| 29 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
is_running: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 30 | |||||||||||
| 31 | 0 | my $pid = $self->_get_pid(); | |||||||||
| 32 | 0 | my $commandline = $self->scan_name(); | |||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | if (defined($pid)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | |||||||||||
| 36 | # use ps to scan for an existing process with this pid | ||||||||||
| 37 | |||||||||||
| 38 | 0 | my $command = "ps -p $pid -o comm="; | |||||||||
| 39 | 0 | my ($output, $rc) = run_cmd($command); | |||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | if ($rc == 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | |||||||||||
| 43 | 0 | foreach my $line (@$output) { | |||||||||
| 44 | |||||||||||
| 45 | 0 | $line = compress(trim($line)); | |||||||||
| 46 | 0 | $self->log->debug(sprintf("\"%s\" = \"%s\"", $commandline, $line)); | |||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | return $pid if ($commandline =~ /$line/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | |||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | return undef; | |||||||||
| 57 | |||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | # ---------------------------------------------------------------------- | ||||||||||
| 61 | # Private Methods | ||||||||||
| 62 | # ---------------------------------------------------------------------- | ||||||||||
| 63 | |||||||||||
| 64 | 1 | 1; | |||||||||
| 65 | |||||||||||
| 66 | __END__ | ||||||||||
| 67 | |||||||||||
| 68 | =head1 NAME | ||||||||||
| 69 | |||||||||||
| 70 | XAS::Lib::PidFile::Unix - A mixin class to scan for processes on Unix | ||||||||||
| 71 | |||||||||||
| 72 | =head1 DESCRIPTION | ||||||||||
| 73 | |||||||||||
| 74 | This is a mixin class to provide process scanning on a Unix platform. It | ||||||||||
| 75 | uses "ps" to do the process scan. | ||||||||||
| 76 | |||||||||||
| 77 | =head1 METHODS | ||||||||||
| 78 | |||||||||||
| 79 | =head2 is_running | ||||||||||
| 80 | |||||||||||
| 81 | Please see L<XAS::Lib::PidFile|XAS::Lib::PidFile> for usage. | ||||||||||
| 82 | |||||||||||
| 83 | =head1 SEE ALSO | ||||||||||
| 84 | |||||||||||
| 85 | =over 4 | ||||||||||
| 86 | |||||||||||
| 87 | =item L<XAS|XAS> | ||||||||||
| 88 | |||||||||||
| 89 | =back | ||||||||||
| 90 | |||||||||||
| 91 | =head1 AUTHOR | ||||||||||
| 92 | |||||||||||
| 93 | Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> | ||||||||||
| 94 | |||||||||||
| 95 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 96 | |||||||||||
| 97 | Copyright (C) 2014 Kevin L. Esteb | ||||||||||
| 98 | |||||||||||
| 99 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 100 | the terms of the Artistic License 2.0. For details, see the full text | ||||||||||
| 101 | of the license at http://www.perlfoundation.org/artistic_license_2_0. | ||||||||||
| 102 | |||||||||||
| 103 | =cut | ||||||||||