File Coverage

blib/lib/Bio/GMOD/Admin/Monitor/httpd.pm
Criterion Covered Total %
statement 15 37 40.5
branch 0 6 0.0
condition 0 2 0.0
subroutine 5 7 71.4
pod 2 2 100.0
total 22 54 40.7


line stmt bran cond sub pod time code
1             package Bio::GMOD::Admin::Monitor::httpd;
2              
3             # Monitor and restart httpd as needed
4              
5 1     1   25892 use strict;
  1         3  
  1         39  
6 1     1   5 use vars qw/@ISA/;
  1         2  
  1         45  
7 1     1   609 use Bio::GMOD::Admin::Monitor;
  1         3  
  1         35  
8 1     1   6 use Bio::GMOD::Util::Rearrange;
  1         2  
  1         50  
9 1     1   1294 use LWP::UserAgent;
  1         56490  
  1         771  
10              
11             @ISA = qw/Bio::GMOD::Admin::Monitor/;
12              
13             # Here, we'll check the status of httpd by actually checking to see
14             # that the website is up.
15             sub check_status {
16 0     0 1   my ($self,@p) = @_;
17 0           my ($site) = rearrange([qw/SITE/],@p);
18              
19 0 0         unless ($site) {
20 0           my $adaptor = $self->adaptor;
21 0           $site = $adaptor->live_url;
22             }
23              
24 0           $self->{testing} = 'httpd';
25 0           $self->{tested_at} = $self->fetch_date;
26              
27 0           my $ua = LWP::UserAgent->new();
28 0           $ua->agent('Bio::GMOD::Admin::Monitor');
29 0           my $request = HTTP::Request->new('GET',$site);
30 0           my $response = $ua->request($request);
31 0 0         my ($string,$status) = $self->set_status(-timing => 'initial',
32             -msg => "Testing httpd at $site",
33             -status => ($response->is_success) ? 'up' : 'down');
34 0           return ($string,$status);
35             }
36              
37              
38             # NOTE! The "final" status is really just whether or not the command
39             # succeeded, not whether the service has been restored!
40             sub restart {
41 0     0 1   my ($self,@p) = @_;
42 0           my ($apachectl) = rearrange([qw/APACHECTL/],@p);
43 0   0       $apachectl ||= '/usr/local/apache/bin/apachectl';
44 0           my $result = system($apachectl,'restart');
45 0           my ($string,$status);
46 0 0         if ($result != 0) {
47 0           ($string,$status) = $self->set_status(-timing => 'final',
48             -msg => "Restarting httpd",
49             -status => 'failed');
50             } else {
51 0           ($string,$status) = $self->set_status(-timing => 'final',
52             -msg => "Restarting httpd",
53             -status => 'succeeded');
54             }
55 0           return ($string,$status);
56             }
57              
58              
59             1;
60              
61              
62             =pod
63              
64             =head1 NAME
65              
66             Bio::GMOD::Admin::Monitor::httpd - Monitor httpd
67              
68             =head1 SYNOPSIS
69              
70             Check that httpd is running at a specific site
71              
72             use Bio::GMOD::Admin::Monitor::httpd;
73             my $gmod = Bio::GMOD::Admin::Monitor::httpd->new(-mod=>'WormBase');
74             my ($result,$status) $gmod->check_status(-site => 'http://www.flybase.org');
75             print "Testing FlyBase status at " . $gmod->tested_at . ": $result";
76              
77             =head1 DESCRIPTION
78              
79             Bio::GMOD::Admin::Monitor::httpd provides methods for monitoring and
80             restarting httpd as necessary at a MOD.
81              
82             =head1 PUBLIC METHODS
83              
84             =over 4
85              
86             =item $gmod->check_status(-site => SITE)
87              
88             Check the status of httpd at a specified site. This is done by
89             fetching the top level URL, assuming that if it can be retrieved that
90             httpd is up.
91              
92             This method returns a two element list comprised of ($string,$status).
93             $string will contain a formatted string indicating the test, time, and
94             result; $status will be boolean true or false indicating the success
95             or failure of the test.
96              
97             This method also populates the object with a variety of status
98             strings. See the "ACCESSOR METHODS" section of Bio::GMOD::Admin::Monitor for
99             additional details.
100              
101             If SITE is not provided, the URL for the live site (fetched from the
102             adaptor for the appropriate MOD) will be used:
103              
104             my $monitor = Bio::GMOD::Admin::Monitor::httpd->new(-mod=>'WormBase');
105             $monitor->check_status(); # Checks the status of http://www.wormbase.org/
106              
107             Note that you must specify the -mod option to new in order for this to
108             work correctly.
109              
110             =item $monitor->restart(-apachectl => APACHECTL);
111              
112             Restart httpd using the apachectl script. If not provided as an
113             option, assumes that apachectl resides at
114             /usr/local/apache/bin/apachectl.
115              
116             This method returns a two element list comprised of ($string,$status).
117             $string will contain a formatted string indicating the test, time, and
118             result; $status will be boolean true or false indicating the success
119             or failure of the test.
120              
121             Like check_status(), this method populates a number of status
122             fields in the object. See the "ACCESSOR METHODS" section of
123             Bio::GMOD::Admin::Monitor for additional details.
124              
125             =back
126              
127             =head1 BUGS
128              
129             None reported.
130              
131             =head1 SEE ALSO
132              
133             L, L
134              
135             =head1 AUTHOR
136              
137             Todd W. Harris Eharris@cshl.orgE.
138              
139             Copyright (c) 2003-2005 Cold Spring Harbor Laboratory.
140              
141             This library is free software; you can redistribute it and/or modify
142             it under the same terms as Perl itself.
143              
144             =cut