| 1 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Footprintless::Service; | ||||||||||||||||||||||||||||
| 5 | 2 | $Footprintless::Service::VERSION = '1.29'; | |||||||||||||||||||||||||||
| 6 | # ABSTRACT: Performs an action on a service. | ||||||||||||||||||||||||||||
| 7 | # PODNAME: Footprintless::Service | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use parent qw(Footprintless::MixableBase); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Footprintless::Command qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | batch_command | ||||||||||||||||||||||||||||
| 14 | command | ||||||||||||||||||||||||||||
| 15 | 2 | ); | |||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Footprintless::CommandOptionsFactory; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Footprintless::InvalidEntityException; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Footprintless::Localhost; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Footprintless::Mixins qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | _command_options | ||||||||||||||||||||||||||||
| 21 | _entity | ||||||||||||||||||||||||||||
| 22 | _run_or_die | ||||||||||||||||||||||||||||
| 23 | 2 | ); | |||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Footprintless::Util qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | invalid_entity | ||||||||||||||||||||||||||||
| 26 | 2 | ); | |||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Log::Any; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | my $logger = Log::Any->get_logger(); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 5 | ▶ | sub kill { | ||||||||||||||||||||||||||
|
Subroutine
kill: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 5 | my ( $self, %options ) = @_; | |||||||||||||||||||||||||||
| 33 | 5 | $self->execute( 'kill', %options ); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 26 | ▶ | sub _command { | ||||||||||||||||||||||||||
|
Subroutine
_command: called CC=13 SCAR=26.8
| |||||||||||||||||||||||||||||
| 37 | 26 | my ( $self, $action ) = @_; | |||||||||||||||||||||||||||
| 38 | 26 | my $command = $self->{spec}{command}; | |||||||||||||||||||||||||||
| 39 | 26 | my $actions_spec = $self->{spec}{actions}{$action}; | |||||||||||||||||||||||||||
| 40 | 26 | ▶ | if ($actions_spec) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 13 | ▶ | if ( $actions_spec->{command} ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 42 | 5 | return $actions_spec->{command}; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | elsif ( $actions_spec->{command_args} ) { | ||||||||||||||||||||||||||||
| 45 | 4 | $action = $actions_spec->{command_args}; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | elsif ( $actions_spec->{use_pid} ) { | ||||||||||||||||||||||||||||
| 48 | invalid_entity( $self->{coordinate}, | ||||||||||||||||||||||||||||
| 49 | "pid_file or pid_command required for [$action]" ) | ||||||||||||||||||||||||||||
| 50 | 4 | ▶ | unless ( $self->{spec}{pid_file} || $self->{spec}{pid_command} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"spec"}{"pid_file"} or $self->{"spec"}{"pid_command"}
MC/DC0%0/2
$self->{"spec"}{"pid_file"} or $self->{"spec"}{"pid_command"}
$self->{"spec"}{"pid_file"}
$self->{"spec"}{"pid_command"}
Truth table33%1/3
A or B
A= $self->{"spec"}{"pid_file"}B= $self->{"spec"}{"pid_command"}
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 4 | my $pid_file = $self->{spec}{pid_file}; | |||||||||||||||||||||||||||
| 53 | my $pid_command = | ||||||||||||||||||||||||||||
| 54 | $pid_file | ||||||||||||||||||||||||||||
| 55 | ? command( | ||||||||||||||||||||||||||||
| 56 | "cat $pid_file", | ||||||||||||||||||||||||||||
| 57 | $self->{command_options}->clone( | ||||||||||||||||||||||||||||
| 58 | hostname => undef, | ||||||||||||||||||||||||||||
| 59 | ssh => undef, | ||||||||||||||||||||||||||||
| 60 | ssh_username => undef, | ||||||||||||||||||||||||||||
| 61 | ) | ||||||||||||||||||||||||||||
| 62 | ) | ||||||||||||||||||||||||||||
| 63 | 4 | ▶ | : $self->{spec}{pid_command}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 4 | ▶ | if ( $action eq 'kill' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 65 | 1 | return "kill -KILL \$($pid_command)"; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | elsif ( $action eq 'status' ) { | ||||||||||||||||||||||||||||
| 68 | 1 | ▶ | my $command_name = $actions_spec->{command_name} || $command || 'command'; | ||||||||||||||||||||||||||
|
Condition40%2/5
$actions_spec->{'command_name'} || $command || 'command'
$actions_spec->{"command_name"} or $command
MC/DC0%0/2
$actions_spec->{'command_name'} || $command || 'command'
$actions_spec->{"command_name"}
$command
Truth table33%1/3
A or B
A= $actions_spec->{"command_name"}B= $command
| |||||||||||||||||||||||||||||
| 69 | 1 | return command( "kill -0 \$($pid_command) 2> /dev/null " | |||||||||||||||||||||||||||
| 70 | . "&& echo '$command_name is running' " | ||||||||||||||||||||||||||||
| 71 | . "|| echo '$command_name is stopped'" ); | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||
| 74 | 2 | invalid_entity( $self->{coordinate}, "use_pid not supported for [$action]" ); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 17 | ▶ | invalid_entity( $self->{coordinate}, "no command specified for [$action]" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | unless ($command); | ||||||||||||||||||||||||||||
| 81 | 17 | return "$command $action"; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 26 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 26 | my ( $self, $action, %options ) = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | my $runner_options = | ||||||||||||||||||||||||||||
| 88 | %options && $options{runner_options} | ||||||||||||||||||||||||||||
| 89 | ? $options{runner_options} | ||||||||||||||||||||||||||||
| 90 | 26 | ▶ | : { out_handle => \*STDOUT }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
%options and $options{"runner_options"}
MC/DC50%1/2
%options and $options{"runner_options"}
%options
$options{"runner_options"}
Truth table66%2/3
A and B
A= %optionsB= $options{"runner_options"}
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 26 | $self->_run_or_die( command( $self->_command($action), $self->{command_options} ), | |||||||||||||||||||||||||||
| 93 | $runner_options ); | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 10 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 97 | 10 | my ( $self, %options ) = @_; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 10 | $self->{entity} = $self->{factory}->entities(); | |||||||||||||||||||||||||||
| 100 | 10 | $self->{spec} = $self->_entity( $self->{coordinate}, 1 ); | |||||||||||||||||||||||||||
| 101 | 10 | $self->{command_options} = $self->_command_options(); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 10 | return $self; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 6 | ▶ | sub start { | ||||||||||||||||||||||||||
|
Subroutine
start: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 6 | my ( $self, %options ) = @_; | |||||||||||||||||||||||||||
| 108 | 6 | $self->execute( 'start', %options ); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 5 | ▶ | sub status { | ||||||||||||||||||||||||||
|
Subroutine
status: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 5 | my ( $self, %options ) = @_; | |||||||||||||||||||||||||||
| 113 | 5 | $self->execute( 'status', %options ); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 5 | ▶ | sub stop { | ||||||||||||||||||||||||||
|
Subroutine
stop: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 5 | my ( $self, %options ) = @_; | |||||||||||||||||||||||||||
| 118 | 5 | $self->execute( 'stop', %options ); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 2 | 1; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||