line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
68192
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
55
|
|
2
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
93
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Footprintless::Service; |
5
|
|
|
|
|
|
|
$Footprintless::Service::VERSION = '1.28'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Performs an action on a service. |
7
|
|
|
|
|
|
|
# PODNAME: Footprintless::Service |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
12
|
use parent qw(Footprintless::MixableBase); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
82
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
120
|
|
12
|
2
|
|
|
|
|
167
|
use Footprintless::Command qw( |
13
|
|
|
|
|
|
|
batch_command |
14
|
|
|
|
|
|
|
command |
15
|
2
|
|
|
2
|
|
1027
|
); |
|
2
|
|
|
|
|
5
|
|
16
|
2
|
|
|
2
|
|
767
|
use Footprintless::CommandOptionsFactory; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
56
|
|
17
|
2
|
|
|
2
|
|
793
|
use Footprintless::InvalidEntityException; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
53
|
|
18
|
2
|
|
|
2
|
|
13
|
use Footprintless::Localhost; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
52
|
|
19
|
2
|
|
|
|
|
129
|
use Footprintless::Mixins qw( |
20
|
|
|
|
|
|
|
_command_options |
21
|
|
|
|
|
|
|
_entity |
22
|
|
|
|
|
|
|
_run_or_die |
23
|
2
|
|
|
2
|
|
812
|
); |
|
2
|
|
|
|
|
7
|
|
24
|
2
|
|
|
|
|
88
|
use Footprintless::Util qw( |
25
|
|
|
|
|
|
|
invalid_entity |
26
|
2
|
|
|
2
|
|
14
|
); |
|
2
|
|
|
|
|
4
|
|
27
|
2
|
|
|
2
|
|
11
|
use Log::Any; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $logger = Log::Any->get_logger(); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub kill { |
32
|
5
|
|
|
5
|
1
|
11
|
my ( $self, %options ) = @_; |
33
|
5
|
|
|
|
|
11
|
$self->execute( 'kill', %options ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _command { |
37
|
26
|
|
|
26
|
|
41
|
my ( $self, $action ) = @_; |
38
|
26
|
|
|
|
|
38
|
my $command = $self->{spec}{command}; |
39
|
26
|
|
|
|
|
38
|
my $actions_spec = $self->{spec}{actions}{$action}; |
40
|
26
|
100
|
|
|
|
43
|
if ($actions_spec) { |
41
|
13
|
100
|
|
|
|
40
|
if ( $actions_spec->{command} ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
42
|
5
|
|
|
|
|
16
|
return $actions_spec->{command}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ( $actions_spec->{command_args} ) { |
45
|
4
|
|
|
|
|
6
|
$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
|
0
|
33
|
|
|
10
|
unless ( $self->{spec}{pid_file} || $self->{spec}{pid_command} ); |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
5
|
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
|
50
|
|
|
|
17
|
: $self->{spec}{pid_command}; |
64
|
4
|
100
|
|
|
|
30
|
if ( $action eq 'kill' ) { |
|
|
100
|
|
|
|
|
|
65
|
1
|
|
|
|
|
4
|
return "kill -KILL \$($pid_command)"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
elsif ( $action eq 'status' ) { |
68
|
1
|
|
50
|
|
|
5
|
my $command_name = $actions_spec->{command_name} || $command || 'command'; |
69
|
1
|
|
|
|
|
7
|
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
|
|
|
|
|
10
|
invalid_entity( $self->{coordinate}, "use_pid not supported for [$action]" ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
17
|
50
|
|
|
|
28
|
invalid_entity( $self->{coordinate}, "no command specified for [$action]" ) |
80
|
|
|
|
|
|
|
unless ($command); |
81
|
17
|
|
|
|
|
61
|
return "$command $action"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub execute { |
85
|
26
|
|
|
26
|
1
|
48
|
my ( $self, $action, %options ) = @_; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $runner_options = |
88
|
|
|
|
|
|
|
%options && $options{runner_options} |
89
|
|
|
|
|
|
|
? $options{runner_options} |
90
|
26
|
100
|
66
|
|
|
115
|
: { out_handle => \*STDOUT }; |
91
|
|
|
|
|
|
|
|
92
|
26
|
|
|
|
|
63
|
$self->_run_or_die( command( $self->_command($action), $self->{command_options} ), |
93
|
|
|
|
|
|
|
$runner_options ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _init { |
97
|
10
|
|
|
10
|
|
17
|
my ( $self, %options ) = @_; |
98
|
|
|
|
|
|
|
|
99
|
10
|
|
|
|
|
63
|
$self->{entity} = $self->{factory}->entities(); |
100
|
10
|
|
|
|
|
28
|
$self->{spec} = $self->_entity( $self->{coordinate}, 1 ); |
101
|
10
|
|
|
|
|
22
|
$self->{command_options} = $self->_command_options(); |
102
|
|
|
|
|
|
|
|
103
|
10
|
|
|
|
|
31
|
return $self; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub start { |
107
|
6
|
|
|
6
|
1
|
34
|
my ( $self, %options ) = @_; |
108
|
6
|
|
|
|
|
11
|
$self->execute( 'start', %options ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub status { |
112
|
5
|
|
|
5
|
1
|
10
|
my ( $self, %options ) = @_; |
113
|
5
|
|
|
|
|
10
|
$self->execute( 'status', %options ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub stop { |
117
|
5
|
|
|
5
|
1
|
9
|
my ( $self, %options ) = @_; |
118
|
5
|
|
|
|
|
12
|
$self->execute( 'stop', %options ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |