| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Clustericious::Command::status; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1019
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
34
|
|
|
5
|
1
|
|
|
1
|
|
23
|
use 5.010001; |
|
|
1
|
|
|
|
|
4
|
|
|
6
|
1
|
|
|
1
|
|
9
|
use Clustericious::Log; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
10
|
|
|
7
|
1
|
|
|
1
|
|
995
|
use Mojo::UserAgent; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
9
|
|
|
8
|
1
|
|
|
1
|
|
29
|
use Clustericious::App; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
9
|
1
|
|
|
1
|
|
31
|
use Clustericious::Config; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
38
|
|
|
10
|
1
|
|
|
1
|
|
8
|
use File::Basename qw( dirname ); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
60
|
|
|
11
|
1
|
|
|
1
|
|
9
|
use base 'Clustericious::Command'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
878
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ABSTRACT: Clustericious command to report status of Clustericious application |
|
14
|
|
|
|
|
|
|
our $VERSION = '1.27'; # VERSION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->attr(description => <<''); |
|
18
|
|
|
|
|
|
|
Report the status of a daemon. |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
__PACKAGE__->attr(usage => <<""); |
|
21
|
|
|
|
|
|
|
usage: $0 status |
|
22
|
|
|
|
|
|
|
Report the status of a clustericious daemon. |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _check_pidfile |
|
25
|
|
|
|
|
|
|
{ |
|
26
|
0
|
|
|
0
|
|
|
my($filename) = @_; |
|
27
|
0
|
0
|
|
|
|
|
return ( state => 'error', message => 'missing pid filename' ) unless $filename; |
|
28
|
0
|
0
|
|
|
|
|
return ( state => 'down', message => 'no pid file' ) unless -e $filename; |
|
29
|
0
|
|
|
|
|
|
my $pid = Mojo::Asset::File->new(path => $filename)->slurp; |
|
30
|
0
|
0
|
|
|
|
|
return ( state => 'down', messasge => 'no pid in file' ) unless $pid; |
|
31
|
0
|
0
|
|
|
|
|
return ( state => 'ok' ) if kill 0, $pid; |
|
32
|
0
|
|
|
|
|
|
return ( state => 'down', message => "Pid $pid in file is not running." ); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _check_database |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
0
|
|
|
0
|
|
|
my($db_class) = @_; |
|
38
|
0
|
|
|
|
|
|
my $db = $db_class->new_or_cached; |
|
39
|
0
|
|
|
|
|
|
my ( $domain, $type ) = ( $db->default_domain, $db->default_type ); |
|
40
|
0
|
|
|
|
|
|
my $dbh = $db->dbh; |
|
41
|
0
|
|
|
|
|
|
my ( $state, $message ); |
|
42
|
0
|
0
|
|
|
|
|
if ($dbh) |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
0
|
|
|
|
|
|
$state = 'ok'; |
|
45
|
0
|
0
|
|
|
|
|
($message) = join ':', grep {defined && length} $dbh->selectrow_array('select current_database(), inet_server_addr(), inet_server_port()'); |
|
|
0
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
else |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
0
|
|
|
|
|
|
$state = 'down'; |
|
50
|
0
|
|
|
|
|
|
$message = $db_class->name; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
return { |
|
53
|
0
|
|
|
|
|
|
name => "database", |
|
54
|
|
|
|
|
|
|
state => $state, |
|
55
|
|
|
|
|
|
|
message => "$domain:$type $message", |
|
56
|
|
|
|
|
|
|
}; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub run |
|
60
|
|
|
|
|
|
|
{ |
|
61
|
0
|
|
|
0
|
1
|
|
my($self, @args) = @_; |
|
62
|
0
|
0
|
|
|
|
|
exit 2 unless $self->app->sanity_check; |
|
63
|
0
|
|
|
|
|
|
my $app = $ENV{MOJO_APP}; |
|
64
|
0
|
|
|
|
|
|
my $conf = $self->app->config; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
eval "require $app"; |
|
67
|
0
|
0
|
|
|
|
|
die $@ if $@; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my @status; # array of { name =>.., state =>.., message =>.. } hashrefs. |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $exe = $0; |
|
72
|
|
|
|
|
|
|
# webserver |
|
73
|
0
|
|
|
|
|
|
for ($self->app->config->start_mode) |
|
74
|
|
|
|
|
|
|
{ |
|
75
|
0
|
0
|
|
|
|
|
push @status, { name => $_, |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
( |
|
77
|
|
|
|
|
|
|
# THIS IS A MESS PLEASE CLEAN IT UP |
|
78
|
|
|
|
|
|
|
/hypnotoad/ ? _check_pidfile($conf->hypnotoad->pid_file(default => dirname($exe).'/hypnotoad.pid')) |
|
79
|
|
|
|
|
|
|
: /apache/ ? _check_pidfile($conf->apache->pid_file) |
|
80
|
|
|
|
|
|
|
: /plackup/ ? _check_pidfile($conf->plackup->pidfile) |
|
81
|
|
|
|
|
|
|
# NB: see http://redmine.lighttpd.net/issues/2137 |
|
82
|
|
|
|
|
|
|
# lighttpd's pid files disappear. Time to switch to nginx? |
|
83
|
|
|
|
|
|
|
: /lighttpd/ ? _check_pidfile($conf->lighttpd->pid_file) |
|
84
|
|
|
|
|
|
|
: ( state => 'error', message => "Status for start_mode $_ is unimplemented." ))}; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Do a HEAD request if the webserver(s) are ok. |
|
88
|
0
|
0
|
|
|
|
|
if ((grep {$_->{state} eq 'ok'} @status)==@status) |
|
|
0
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
{ |
|
90
|
0
|
|
|
|
|
|
my $res = Mojo::UserAgent->new->head($conf->url)->res; |
|
91
|
0
|
|
0
|
|
|
|
printf "%10s : %-10s (%s %s)\n", "url", $conf->url, $res->code || '?', $res->message || ''; |
|
|
|
|
0
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Database |
|
95
|
0
|
0
|
|
|
|
|
if ( $INC{'Rose/Planter/DB.pm'} ) |
|
96
|
|
|
|
|
|
|
{ |
|
97
|
0
|
0
|
|
|
|
|
if ( my $db_class = Rose::Planter::DB->registered_by($app) ) |
|
98
|
|
|
|
|
|
|
{ |
|
99
|
0
|
|
|
|
|
|
push @status, _check_database($db_class); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $ok; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Send as YAML if requested? |
|
106
|
0
|
|
|
|
|
|
for (@status) |
|
107
|
|
|
|
|
|
|
{ |
|
108
|
0
|
|
0
|
|
|
|
$_->{message} &&= "($_->{message})";; |
|
109
|
0
|
|
0
|
|
|
|
$_->{message} ||= ""; |
|
110
|
0
|
|
|
|
|
|
printf "%10s : %-10s %s\n", @$_{qw/name state message/}; |
|
111
|
0
|
0
|
0
|
|
|
|
$ok //= 1 if $_->{state} eq 'ok'; |
|
112
|
0
|
0
|
|
|
|
|
$ok = 0 if $_->{state} ne 'ok'; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
exit($ok ? 0 : 2); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=pod |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=encoding UTF-8 |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 NAME |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Clustericious::Command::status - Clustericious command to report status of Clustericious application |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 VERSION |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
version 1.27 |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
% yourapp status |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Report the status of a running clustericious daemon, based on its start_mode. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L<Clustericious> |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 AUTHOR |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Original author: Brian Duggan |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Current maintainer: Graham Ollis E<lt>plicease@cpan.orgE<gt> |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Contributors: |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Curt Tilmes |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Yanick Champoux |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This software is copyright (c) 2013 by NASA GSFC. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
163
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |