line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ubic::Ping::Service; |
2
|
|
|
|
|
|
|
$Ubic::Ping::Service::VERSION = '1.59'; |
3
|
|
|
|
|
|
|
# ABSTRACT: ubic.ping service |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
511
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Ubic::Service::Common; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
9
|
1
|
|
|
1
|
|
2
|
use Ubic::Daemon qw(:all); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
4
|
use Ubic::Result qw(result); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
11
|
1
|
|
|
1
|
|
3
|
use Ubic::UA; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
12
|
1
|
|
|
1
|
|
2
|
use POSIX; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
13
|
1
|
|
|
1
|
|
1282
|
use Time::HiRes qw(sleep); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
67
|
use Ubic::Settings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
3
|
use Config; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
255
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
0
|
|
0
|
0
|
1
|
|
my $port = $ENV{UBIC_SERVICE_PING_PORT} || 12345; |
21
|
0
|
|
|
|
|
|
my $pidfile = Ubic::Settings->data_dir."/ubic-ping.pid"; |
22
|
0
|
|
0
|
|
|
|
my $log = $ENV{UBIC_SERVICE_PING_LOG} || '/dev/null'; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $perl = $Config{perlpath}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Ubic::Service::Common->new({ |
27
|
|
|
|
|
|
|
start => sub { |
28
|
0
|
|
|
0
|
|
|
my $pid; |
29
|
0
|
|
|
|
|
|
start_daemon({ |
30
|
|
|
|
|
|
|
bin => qq{$perl -MUbic::Ping -e 'Ubic::Ping->new($port)->run;'}, |
31
|
|
|
|
|
|
|
name => 'ubic.ping', |
32
|
|
|
|
|
|
|
pidfile => $pidfile, |
33
|
|
|
|
|
|
|
stdout => $log, |
34
|
|
|
|
|
|
|
stderr => $log, |
35
|
|
|
|
|
|
|
ubic_log => $log, |
36
|
|
|
|
|
|
|
}); |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
stop => sub { |
39
|
0
|
|
|
0
|
|
|
stop_daemon($pidfile); |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
status => sub { |
42
|
0
|
|
|
0
|
|
|
my $daemon = check_daemon($pidfile); |
43
|
0
|
0
|
|
|
|
|
unless ($daemon) { |
44
|
0
|
|
|
|
|
|
return 'not running'; |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
|
my $ua = Ubic::UA->new(timeout => 1); |
47
|
0
|
|
|
|
|
|
my $response = $ua->get("http://127.0.0.1:$port/ping"); |
48
|
0
|
0
|
|
|
|
|
if ($response->{error}) { |
49
|
0
|
|
|
|
|
|
return result('broken', $response->{error}); |
50
|
|
|
|
|
|
|
} |
51
|
0
|
0
|
0
|
|
|
|
if ($response->{body} =~ /^ok$/ and $response->{code} == 200) { |
52
|
0
|
|
|
|
|
|
return result('running', "pid ".$daemon->pid); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
0
|
|
|
|
|
|
return result('broken', $response->{body}); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
}, |
58
|
0
|
|
|
|
|
|
port => $port, |
59
|
|
|
|
|
|
|
timeout_options => { start => { step => 0.1, trials => 8 }}, |
60
|
|
|
|
|
|
|
}); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |