/usr/share/perl5/RunApp/Apache.pm is in librunapp-perl 0.13-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | package RunApp::Apache;
use strict;
use File::Spec::Functions qw(catfile catdir);
use base qw(RunApp); # child of RunApp because of build
use File::Copy qw(copy);
use File::Path;
sub get_info {
my $self = shift;
my $info;
my $ret = `$self->{httpd} -V`;
($info->{AP_VERSION}) = $ret =~ m{version: Apache/(\d)};
for ($ret =~ m/-D\s*(\S*)/mg) {
my ($key, $value) = m/^(\w+)(?:="?(.*?)"?)?$/;
die $_ unless defined $key;
$info->{$key} = defined $value ? $value : 1;
}
if ($self->{apxs}) {
$info->{$_} = $self->ap_query ($_) for @_;
}
return $info;
}
sub ap_query {
my ($self, $var) = @_;
my $ret = `$self->{apxs} -q $var`;
chomp $ret;
return $ret;
}
sub new {
my $class = shift;
my $self = bless {}, $class;
%$self = @_;
my %ctlarg;
if ($self->{apxs}) {
my $httpd = catfile($self->ap_query ('SBINDIR'), $self->ap_query ('TARGET'));
if (defined $self->{httpd} && $self->{httpd} ne $httpd) {
warn ". Warning: httpd setting disagreed with apxs\n";
}
$self->{httpd} = $httpd;
}
$self->{ctl_file} = catfile($self->{root}, "apachectl");
$self->{config_file} = catfile($self->{root}, "conf", 'httpd.conf');
$self->{mime_file} ||= catfile($self->{root}, "conf", 'mime.types');
$self->{CONF} ||= 'RunApp::Template::Apache';
unless ($self->{CTL}) {
$self->{CTL} = 'RunApp::Control::AppControl';
%ctlarg = ( args => ['-f', $self->{config_file}],
binary => $self->{httpd},
CONTROL => 'App::Control::Apache',
);
}
$self->load($_) for @{$self}{qw/CONF CTL/};
$self->services ( conf => $self->{CONF}->new (file => $self->{config_file}),
ctl => $self->{CTL}->new (file => $self->{ctl_file}, %ctlarg)
);
return $self;
}
sub build {
my ($self, $conf) = @_;
my $info = $self->get_info ('LIBEXECDIR');
undef $conf->{logs} if ref $conf->{logs}; # XXX: something else
$conf->{logs} ||= catfile($self->{root}, 'logs');
$conf->{pidfile} ||= catfile($conf->{logs}, 'httpd.pid');
$self->{_debug} = catfile($conf->{logs}, 'error_log');
mkpath [catfile ($self->{root}, 'conf'),
$conf->{logs}] or die $!
unless -d $self->{root};
my $apacheconf = {
MinSpareServers => 2,
MaxSpareServers => 2,
StartServers => 2,
MaxClients => 100,
MaxRequestsPerChild => 100,
user => (getpwuid($>) || ''),
group => (getgrgid($)) || ''),
};
# final tweak
my $combined = {%$apacheconf, %$self, %$conf, %$info};
# they don't like multi-request in a process.
$combined->{MaxRequestsPerChild} = 1 if $combined->{cover} || $combined->{profiler};
$self->SUPER::build ($combined);
my $mimefile = $info->{TYPES_CONFIG_FILE} || $info->{AP_TYPES_CONFIG_FILE};
$mimefile = catfile($info->{HTTPD_ROOT}, $mimefile)
unless File::Spec->file_name_is_absolute( $mimefile );
if (-r $mimefile) {
copy ($mimefile, $self->{mime_file});
}
else {
warn ". Warning: cant find $mimefile\n";
}
chmod 0755, $self->{ctl_file};
}
sub report {
my ($self, $conf) = @_;
return unless $self->{report};
print "Point your browser at the following URL to see the website:\n";
for (qw/port port_https/) {
next unless $conf->{$_};
print "http://$conf->{hostname}:$conf->{$_}/\n";
}
}
sub debug {
my ($self) = @_;
return unless $self->{_debug};
if (fork) {
return;
}
else {
system ('tail', -f => $self->{_debug});
exit;
}
}
sub dispatch {
my ($self, $cmd) = @_;
#warn ". $cmd => $self->{httpd}\n";
$self->{services}->{ctl}->$cmd;
}
1;
=head1 NAME
RunApp::Apache - Apache control for RunApp
=head1 SYNOPSIS
use RunApp::Apache;
$apache = RunApp::Apache->new
(root => "/tmp/apache_run",
report => 1,
apxs => '/usr/local/sbin/apxs',
# httpd => '/usr/local/sbin/httpd',
required_modules => ["log_config", "alias", "perl", "mime"],
config_block => q{
[% IF AP_VERSION == 2 %]
eval { use Apache2 };
eval { use Apache::compat };
[% END %]
<Location /myapp>
AllowOverride None
SetHandler perl-script
PerlSetVar approot [% cwd %]
PerlHandler MyApp
Options +ExecCGI
</Location>
});
=head1 DESCRIPTION
This is the class for defining a apache web server to be used in
L<RunApp>.
=head1 CONSTRUCTOR
=head2 new (%arg)
Required arg:
=over
=item root
The root for the apache instance.
=item apxs
=item httpd
If C<apxs> is specified, C<httpd> will be derived from it.
=item required_modules
A arrayref to the apache modules required.
=item config_block
The config block that will be the I<extra> block in the template used
by L<RunApp::Template::Apache>.
=item CTL
The class for handling apachectl. The default is
L<RunApp::Control::AppControl>. You can also use
L<RunApp::Control::ApacheCtl>.
=item CONF
The class for handling apache config. The default is
L<RunApp::Template::Apache>. It is used in the C<build> phase of
L<RunApp>
=back
=cut
=head1 SEE ALSO
L<RunApp>, L<RunApp::Control::Apache>, L<RunApp::Template::Apache>, L<App::Control>
=head1 AUTHORS
Chia-liang Kao <clkao@clkao.org>
Refactored from works by Leon Brocard E<lt>acme@astray.comE<gt> and
Tom Insam E<lt>tinsam@fotango.comE<gt>.
=head1 COPYRIGHT
Copyright (C) 2002-5, Fotango Ltd.
This module is free software; you can redistribute it or modify it
under the same terms as Perl itself.
=cut
1;
|