| 1 | package Toadfarm::Command::status; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Mojo::Base 'Toadfarm::Command::start'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use File::Basename 'dirname'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Mojo::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | has description => 'Toadfarm: Get status from the server'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 7 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 12 | 7 | my $moniker = $self->app->moniker; | |||||||||||||||||||||||||||
| 13 | 7 | my $pid_file = $self->_pid_file; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # 0 program is running or service is OK | ||||||||||||||||||||||||||||
| 16 | # 1 program is dead and /var/run pid file exists | ||||||||||||||||||||||||||||
| 17 | # 3 program is not running | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 5 | ▶ | unless (-e $pid_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 2 | return $self->_end(3, 'no pid file'); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | my ($pid) = Mojo::File->new($pid_file)->slurp =~ /(\d+)/; | |||||||||||||||||||||||||||
| 24 | 3 | ▶ | if ($pid and !kill 0, $pid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pid and not kill(0, $pid)
MC/DC50%1/2
$pid and not kill(0, $pid)
$pid
not kill(0, $pid)
Truth table66%2/3
A and not(B)
A= $pidB= not kill(0, $pid)
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | $pid ||= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$pid ||= 0
MC/DC0%0/1
$pid ||= 0
$pid
Truth table50%1/2
A
A= $pid
| |||||||||||||||||||||||||||||
| 26 | 1 | return $self->_end(1, "but $pid_file exists"); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | return $self->_end(0); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 5 | ▶ | sub _end { | ||||||||||||||||||||||||||
|
Subroutine
_end: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 33 | 5 | my ($self, $exit, $message) = @_; | |||||||||||||||||||||||||||
| 34 | 5 | ▶ | my $format = $exit ? 'Process %s is not running (%s)' : 'Process %s is running'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 5 | $self->_printf(" * $format\n", $self->app->moniker, $message); | |||||||||||||||||||||||||||
| 36 | 5 | ▶ | return $exit if $ENV{TOADFARM_NO_EXIT}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | exit $exit; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | 1; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =encoding utf8 | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head1 NAME | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | Toadfarm::Command::status - Get status from a Toadfarm DSL script | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | L<Toadfarm::Command::status> is a command for retrieving status from a | ||||||||||||||||||||||||||||
| 51 | L<Toadfarm> application. | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | $ /path/to/script.pl status | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head2 description | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Short description of command, used for the command list. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head1 METHODS | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head2 run | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Run command. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Copyright (C) 2014, Jan Henning Thorsen | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 74 | the terms of the Artistic License version 2.0. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | Jan Henning Thorsen - C<jhthorsen@cpan.org> | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =cut | ||||||||||||||||||||||||||||