line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ubic::Service::Skeleton; |
2
|
|
|
|
|
|
|
$Ubic::Service::Skeleton::VERSION = '1.58_01'; # TRIAL |
3
|
25
|
|
|
25
|
|
9865
|
use strict; |
|
25
|
|
|
|
|
48
|
|
|
25
|
|
|
|
|
783
|
|
4
|
25
|
|
|
25
|
|
127
|
use warnings; |
|
25
|
|
|
|
|
45
|
|
|
25
|
|
|
|
|
1104
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: skeleton of any service with common start/stop logic |
7
|
|
|
|
|
|
|
|
8
|
25
|
|
|
25
|
|
403
|
use Ubic::Result qw(result); |
|
25
|
|
|
|
|
42
|
|
|
25
|
|
|
|
|
1844
|
|
9
|
25
|
|
|
25
|
|
156
|
use Scalar::Util qw(blessed); |
|
25
|
|
|
|
|
32
|
|
|
25
|
|
|
|
|
1497
|
|
10
|
25
|
|
|
25
|
|
9784
|
use Time::HiRes qw(sleep); |
|
25
|
|
|
|
|
25492
|
|
|
25
|
|
|
|
|
197
|
|
11
|
25
|
|
|
25
|
|
14748
|
use Ubic::Service::Utils qw(wait_for_status); |
|
25
|
|
|
|
|
55
|
|
|
25
|
|
|
|
|
1906
|
|
12
|
|
|
|
|
|
|
|
13
|
25
|
|
|
25
|
|
189
|
use parent qw(Ubic::Service); |
|
25
|
|
|
|
|
38
|
|
|
25
|
|
|
|
|
190
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub status { |
16
|
170
|
|
|
170
|
1
|
671
|
my ($self) = @_; |
17
|
170
|
|
|
|
|
923
|
my $result = $self->status_impl; |
18
|
170
|
|
100
|
|
|
3011
|
$result ||= 'unknown'; |
19
|
170
|
|
|
|
|
852
|
$result = result($result); |
20
|
170
|
|
|
|
|
1250
|
return $result; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub start { |
24
|
41
|
|
|
41
|
1
|
2314
|
my ($self) = @_; |
25
|
|
|
|
|
|
|
|
26
|
41
|
|
|
|
|
203
|
my $status = $self->status; |
27
|
41
|
100
|
|
|
|
168
|
if ($status->status eq 'running') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
28
|
2
|
|
|
|
|
12
|
return 'already running'; # TODO - update $status field instead? |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif ($status->status eq 'not running') { |
31
|
37
|
|
|
|
|
254
|
return $self->_do_start; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif ($status->status eq 'broken') { |
34
|
|
|
|
|
|
|
# checks inside _do_start and _do_stop guarantee correct status |
35
|
2
|
|
|
|
|
21
|
$self->_do_stop; |
36
|
1
|
|
|
|
|
13
|
return $self->_do_start; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
0
|
|
|
|
|
0
|
die result('unknown', "wrong status '$status'"); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub stop { |
44
|
29
|
|
|
29
|
1
|
2000261
|
my ($self) = @_; |
45
|
|
|
|
|
|
|
|
46
|
29
|
|
|
|
|
138
|
my $status = $self->status; |
47
|
29
|
100
|
|
|
|
129
|
if ($status->status eq 'not running') { |
48
|
2
|
|
|
|
|
9
|
return 'not running'; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
27
|
|
|
|
|
217
|
return $self->_do_stop; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub status_impl { |
55
|
0
|
|
|
0
|
1
|
0
|
die 'not implemented'; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub start_impl { |
59
|
0
|
|
|
0
|
1
|
0
|
die 'not implemented'; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub stop_impl { |
63
|
0
|
|
|
0
|
1
|
0
|
die 'not implemented'; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub timeout_options { |
67
|
45
|
|
|
45
|
1
|
1648
|
return {}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
##### internal methods ###### |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _do_start { |
74
|
38
|
|
|
38
|
|
93
|
my ($self) = @_; |
75
|
|
|
|
|
|
|
|
76
|
38
|
|
|
|
|
84
|
my $status; |
77
|
|
|
|
|
|
|
|
78
|
38
|
|
|
|
|
155
|
my $start_result = $self->start_impl; |
79
|
29
|
100
|
66
|
|
|
661
|
if (blessed($start_result) and $start_result->isa('Ubic::Result::Class')) { |
80
|
2
|
|
|
|
|
5
|
$status = $start_result; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
29
|
100
|
66
|
|
|
170
|
if (not $status or $status->type eq 'starting') { |
84
|
|
|
|
|
|
|
$status = wait_for_status({ |
85
|
|
|
|
|
|
|
service => $self, |
86
|
|
|
|
|
|
|
expect_status => ['running', 'not running'], |
87
|
27
|
50
|
|
|
|
414
|
%{ $self->timeout_options->{start} || {} }, |
|
27
|
|
|
|
|
957
|
|
88
|
|
|
|
|
|
|
}); |
89
|
27
|
50
|
|
|
|
124
|
if ($status->status eq 'running') { |
90
|
27
|
|
|
|
|
141
|
$status->type('started'); # fake status to report correct action (hopefully) |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
29
|
50
|
|
|
|
334
|
if (not $status) { |
95
|
0
|
|
|
|
|
0
|
die result('unknown', 'no result'); |
96
|
|
|
|
|
|
|
} |
97
|
29
|
50
|
|
|
|
115
|
if ($status->status eq 'running') { |
98
|
29
|
|
|
|
|
513
|
return $status; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
0
|
|
|
|
|
0
|
die result($status, 'start failed'); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _do_stop { |
106
|
29
|
|
|
29
|
|
65
|
my ($self) = @_; |
107
|
29
|
|
|
|
|
47
|
my $status; |
108
|
|
|
|
|
|
|
|
109
|
29
|
|
|
|
|
420
|
my $stop_result = $self->stop_impl; |
110
|
28
|
100
|
66
|
|
|
886
|
if (blessed($stop_result) and $stop_result->isa('Ubic::Result::Class')) { |
111
|
2
|
|
|
|
|
4
|
$status = $stop_result; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
28
|
100
|
66
|
|
|
135
|
if (not $status or $status->type eq 'stopping') { |
115
|
|
|
|
|
|
|
$status = wait_for_status({ |
116
|
|
|
|
|
|
|
service => $self, |
117
|
|
|
|
|
|
|
expect_status => ['not running'], |
118
|
26
|
50
|
|
|
|
133
|
%{ $self->timeout_options->{stop} || {} }, |
|
26
|
|
|
|
|
155
|
|
119
|
|
|
|
|
|
|
}); |
120
|
26
|
50
|
|
|
|
121
|
if ($status->status eq 'not running') { |
121
|
26
|
|
|
|
|
99
|
$status->type('stopped'); # fake status to report correct action (hopefully) |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
28
|
50
|
|
|
|
272
|
if (not $status) { |
126
|
0
|
|
|
|
|
0
|
die result('unknown', 'no result'); |
127
|
|
|
|
|
|
|
} |
128
|
28
|
50
|
|
|
|
162
|
if ($status->status eq 'not running') { |
129
|
28
|
|
|
|
|
195
|
return $status; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else { |
132
|
0
|
|
|
|
|
|
die result($status, 'stop failed'); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |