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