/
c3mc-app-port-checkok
executable file
·53 lines (39 loc) · 1.26 KB
/
c3mc-app-port-checkok
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/data/Software/mydan/perl/bin/perl -I/data/Software/mydan/Connector/lib
use strict;
use warnings;
use YAML::XS;
use LWP::UserAgent;
=head1 SYNOPSIS
$0
=cut
$|++;
my $ua = LWP::UserAgent->new();
$ua->agent('Mozilla/9 [en] (Centos; Linux)');
$ua->timeout( 5 );
sub chk
{
my $port = shift @_;
die "port err" unless $port && $port =~ /^\d+$/;
my $res = $ua->get( "http://127.0.0.1:$port/mon" );
return if $res->is_success && $res->content =~ /ok/;
warn "kill port $port";
system '/usr/sbin/lsof -i:'.$port.'|tail -n 1|awk \'{print $2}\'|xargs -i{} kill {}';
}
sub checkok
{
my $name = shift @_;
my $Config = eval{ YAML::XS::LoadFile "/data/Software/mydan/$name/config/Config" };
die "load config fail: $@" if $@;
die "load Config fail: $!" unless $Config;
my $envname = `cat /data/Software/mydan/$name/conf/envname`;
chomp $envname;
die "envname undef" unless $envname;
die "envname $envname undef in Config" unless $Config = $Config->{$envname};
die "port undef" unless my $port = $Config->{port};
for my $c ( values %$port )
{
next unless $c->{from} && $c->{to};
map{ chk( $_ ) } $c->{from} .. $c->{to};
}
}
map{ checkok($_) }qw( JOB CI Connector AGENT JOBX );