[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.9.7-786-g8fa6764
Chia-liang Kao
clkao at bestpractical.com
Thu Dec 9 04:22:51 EST 2010
The branch, 3.9-trunk has been updated
via 8fa6764471a147b98223e7245ca06fc38903ed17 (commit)
via 6db68f8ccc4cfddeaea5da73eef975601c65d3d5 (commit)
from 0994a8e4f563d7d0b6e6880389e259e2a2dd66fb (commit)
Summary of changes:
docs/web_deployment.pod | 4 +
lib/RT/Test.pm | 178 +--------------------------------------------
lib/RT/Test/Apache.pm | 188 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 194 insertions(+), 176 deletions(-)
create mode 100644 lib/RT/Test/Apache.pm
- Log -----------------------------------------------------------------
commit 6db68f8ccc4cfddeaea5da73eef975601c65d3d5
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Wed Dec 8 00:12:53 2010 +0800
move apache related test helpers to rt::test::apache.
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 1277b04..b267cf6 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1258,147 +1258,13 @@ sub start_apache_server {
my $self = shift;
my $variant = shift || 'mod_perl';
- my %info = $self->apache_server_info( variant => $variant );
-
- Test::More::diag(do {
- open my $fh, '<', $tmp{'config'}{'RT'};
- local $/;
- <$fh>
- });
-
- my $tmpl = File::Spec->rel2abs( File::Spec->catfile(
- 't', 'data', 'configs',
- 'apache'. $info{'version'} .'+'. $variant .'.conf'
- ) );
- my %opt = (
- listen => $port,
- server_root => $info{'HTTPD_ROOT'} || $ENV{'HTTPD_ROOT'}
- || Test::More::BAIL_OUT("Couldn't figure out server root"),
- document_root => $RT::MasonComponentRoot,
- tmp_dir => "$tmp{'directory'}",
- rt_bin_path => $RT::BinPath,
- rt_sbin_path => $RT::SbinPath,
- rt_site_config => $ENV{'RT_SITE_CONFIG'},
- );
- foreach (qw(log pid lock)) {
- $opt{$_ .'_file'} = File::Spec->catfile(
- "$tmp{'directory'}", "apache.$_"
- );
- }
- {
- my $method = 'apache_'.$variant.'_server_options';
- $self->$method( \%info, \%opt );
- }
- $tmp{'config'}{'apache'} = File::Spec->catfile(
- "$tmp{'directory'}", "apache.conf"
- );
- $self->process_in_file(
- in => $tmpl,
- out => $tmp{'config'}{'apache'},
- options => \%opt,
- );
-
- $self->fork_exec($info{'executable'}, '-f', $tmp{'config'}{'apache'});
- my $pid = do {
- my $tries = 10;
- while ( !-e $opt{'pid_file'} ) {
- $tries--;
- last unless $tries;
- sleep 1;
- }
- Test::More::BAIL_OUT("Couldn't start apache server, no pid file")
- unless -e $opt{'pid_file'};
- open my $pid_fh, '<', $opt{'pid_file'}
- or Test::More::BAIL_OUT("Couldn't open pid file: $!");
- my $pid = <$pid_fh>;
- chomp $pid;
- $pid;
- };
-
- Test::More::ok($pid, "Started apache server #$pid");
-
+ require RT::Test::Apache;
+ my $pid = RT::Test::Apache->start_server($variant || 'mod_perl', $port, \%tmp);
push @SERVERS, $pid;
return (RT->Config->Get('WebURL'), RT::Test::Web->new);
}
-sub apache_server_info {
- my $self = shift;
- my %res = @_;
-
- my $bin = $res{'executable'} = $ENV{'RT_TEST_APACHE'}
- || $self->find_apache_server
- || Test::More::BAIL_OUT("Couldn't find apache server, use RT_TEST_APACHE");
-
- Test::More::diag("Using '$bin' apache executable for testing")
- if $ENV{'TEST_VERBOSE'};
-
- my $info = `$bin -V`;
- ($res{'version'}) = ($info =~ m{Server\s+version:\s+Apache/(\d+\.\d+)\.});
- Test::More::BAIL_OUT(
- "Couldn't figure out version of the server"
- ) unless $res{'version'};
-
- my %opts = ($info =~ m/^\s*-D\s+([A-Z_]+?)(?:="(.*)")$/mg);
- %res = (%res, %opts);
-
- $res{'modules'} = [
- map {s/^\s+//; s/\s+$//; $_}
- grep $_ !~ /Compiled in modules/i,
- split /\r*\n/, `$bin -l`
- ];
-
- return %res;
-}
-
-sub apache_mod_perl_server_options {
- my $self = shift;
- my %info = %{ shift() };
- my $current = shift;
-
- my %required_modules = (
- '2.2' => [qw(authz_host env alias perl)],
- );
- my @mlist = @{ $required_modules{ $info{'version'} } };
-
- $current->{'load_modules'} = '';
- foreach my $mod ( @mlist ) {
- next if grep $_ =~ /^(mod_|)$mod\.c$/, @{ $info{'modules'} };
-
- $current->{'load_modules'} .=
- "LoadModule ${mod}_module modules/mod_${mod}.so\n";
- }
- return;
-}
-
-sub apache_fastcgi_server_options {
- my $self = shift;
- my %info = %{ shift() };
- my $current = shift;
-
- my %required_modules = (
- '2.2' => [qw(authz_host env alias mime fastcgi)],
- );
- my @mlist = @{ $required_modules{ $info{'version'} } };
-
- $current->{'load_modules'} = '';
- foreach my $mod ( @mlist ) {
- next if grep $_ =~ /^(mod_|)$mod\.c$/, @{ $info{'modules'} };
-
- $current->{'load_modules'} .=
- "LoadModule ${mod}_module modules/mod_${mod}.so\n";
- }
- return;
-}
-
-sub find_apache_server {
- my $self = shift;
- return $_ foreach grep defined,
- map $self->find_executable($_),
- qw(httpd apache apache2 apache1);
- return undef;
-}
-
sub stop_server {
my $self = shift;
@@ -1450,46 +1316,6 @@ sub find_executable {
return undef;
}
-sub fork_exec {
- my $self = shift;
-
- my $pid = fork;
- unless ( defined $pid ) {
- die "cannot fork: $!";
- } elsif ( !$pid ) {
- exec @_;
- die "can't exec `". join(' ', @_) ."` program: $!";
- } else {
- return $pid;
- }
-}
-
-sub process_in_file {
- my $self = shift;
- my %args = ( in => undef, options => undef, @_ );
-
- my $text = $self->file_content( $args{'in'} );
- while ( my ($opt) = ($text =~ /\%\%(.+?)\%\%/) ) {
- my $value = $args{'options'}{ lc $opt };
- die "no value for $opt" unless defined $value;
-
- $text =~ s/\%\%\Q$opt\E\%\%/$value/g;
- }
-
- my ($out_fh, $out_conf);
- unless ( $args{'out'} ) {
- ($out_fh, $out_conf) = tempfile();
- } else {
- $out_conf = $args{'out'};
- open $out_fh, '>', $out_conf
- or die "couldn't open '$out_conf': $!";
- }
- print $out_fh $text;
- seek $out_fh, 0, 0;
-
- return ($out_fh, $out_conf);
-}
-
sub diag {
return unless $ENV{RT_TEST_VERBOSE} || $ENV{TEST_VERBOSE};
goto \&Test::More::diag;
diff --git a/lib/RT/Test/Apache.pm b/lib/RT/Test/Apache.pm
new file mode 100644
index 0000000..f9c56d6
--- /dev/null
+++ b/lib/RT/Test/Apache.pm
@@ -0,0 +1,188 @@
+package RT::Test::Apache;
+use strict;
+use warnings;
+
+my $apache_module_prefix = 'modules';
+
+sub start_server {
+ my ($self, $variant, $port, $tmp) = @_;
+ my %tmp = %$tmp;
+ my %info = $self->apache_server_info( variant => $variant );
+
+ Test::More::diag(do {
+ open my $fh, '<', $tmp{'config'}{'RT'};
+ local $/;
+ <$fh>
+ });
+
+ my $tmpl = File::Spec->rel2abs( File::Spec->catfile(
+ 't', 'data', 'configs',
+ 'apache'. $info{'version'} .'+'. $variant .'.conf'
+ ) );
+ my %opt = (
+ listen => $port,
+ server_root => $info{'HTTPD_ROOT'} || $ENV{'HTTPD_ROOT'}
+ || Test::More::BAIL_OUT("Couldn't figure out server root"),
+ document_root => $RT::MasonComponentRoot,
+ tmp_dir => "$tmp{'directory'}",
+ rt_bin_path => $RT::BinPath,
+ rt_sbin_path => $RT::SbinPath,
+ rt_site_config => $ENV{'RT_SITE_CONFIG'},
+ );
+ foreach (qw(log pid lock)) {
+ $opt{$_ .'_file'} = File::Spec->catfile(
+ "$tmp{'directory'}", "apache.$_"
+ );
+ }
+ {
+ my $method = 'apache_'.$variant.'_server_options';
+ $self->$method( \%info, \%opt );
+ }
+ $tmp{'config'}{'apache'} = File::Spec->catfile(
+ "$tmp{'directory'}", "apache.conf"
+ );
+ $self->process_in_file(
+ in => $tmpl,
+ out => $tmp{'config'}{'apache'},
+ options => \%opt,
+ );
+
+ $self->fork_exec($info{'executable'}, '-f', $tmp{'config'}{'apache'});
+ my $pid = do {
+ my $tries = 10;
+ while ( !-e $opt{'pid_file'} ) {
+ $tries--;
+ last unless $tries;
+ sleep 1;
+ }
+ Test::More::BAIL_OUT("Couldn't start apache server, no pid file")
+ unless -e $opt{'pid_file'};
+ open my $pid_fh, '<', $opt{'pid_file'}
+ or Test::More::BAIL_OUT("Couldn't open pid file: $!");
+ my $pid = <$pid_fh>;
+ chomp $pid;
+ $pid;
+ };
+
+ Test::More::ok($pid, "Started apache server #$pid");
+ return $pid;
+}
+
+sub apache_server_info {
+ my $self = shift;
+ my %res = @_;
+
+ my $bin = $res{'executable'} = $ENV{'RT_TEST_APACHE'}
+ || $self->find_apache_server
+ || Test::More::BAIL_OUT("Couldn't find apache server, use RT_TEST_APACHE");
+
+ Test::More::diag("Using '$bin' apache executable for testing")
+ if $ENV{'TEST_VERBOSE'};
+
+ my $info = `$bin -V`;
+ ($res{'version'}) = ($info =~ m{Server\s+version:\s+Apache/(\d+\.\d+)\.});
+ Test::More::BAIL_OUT(
+ "Couldn't figure out version of the server"
+ ) unless $res{'version'};
+
+ my %opts = ($info =~ m/^\s*-D\s+([A-Z_]+?)(?:="(.*)")$/mg);
+ %res = (%res, %opts);
+
+ $res{'modules'} = [
+ map {s/^\s+//; s/\s+$//; $_}
+ grep $_ !~ /Compiled in modules/i,
+ split /\r*\n/, `$bin -l`
+ ];
+
+ return %res;
+}
+
+sub apache_mod_perl_server_options {
+ my $self = shift;
+ my %info = %{ shift() };
+ my $current = shift;
+
+ my %required_modules = (
+ '2.2' => [qw(authz_host env alias perl)],
+ );
+ my @mlist = @{ $required_modules{ $info{'version'} } };
+
+ $current->{'load_modules'} = '';
+ foreach my $mod ( @mlist ) {
+ next if grep $_ =~ /^(mod_|)$mod\.c$/, @{ $info{'modules'} };
+
+ $current->{'load_modules'} .=
+ "LoadModule ${mod}_module $apache_module_prefix/mod_${mod}.so\n";
+ }
+ return;
+}
+
+sub apache_fastcgi_server_options {
+ my $self = shift;
+ my %info = %{ shift() };
+ my $current = shift;
+
+ my %required_modules = (
+ '2.2' => [qw(authz_host env alias mime fastcgi)],
+ );
+ my @mlist = @{ $required_modules{ $info{'version'} } };
+
+ $current->{'load_modules'} = '';
+ foreach my $mod ( @mlist ) {
+ next if grep $_ =~ /^(mod_|)$mod\.c$/, @{ $info{'modules'} };
+
+ $current->{'load_modules'} .=
+ "LoadModule ${mod}_module $apache_module_prefix/mod_${mod}.so\n";
+ }
+ return;
+}
+
+sub find_apache_server {
+ my $self = shift;
+ return $_ foreach grep defined,
+ map RT::Test->find_executable($_),
+ qw(httpd apache apache2 apache1);
+ return undef;
+}
+
+sub fork_exec {
+ my $self = shift;
+
+ my $pid = fork;
+ unless ( defined $pid ) {
+ die "cannot fork: $!";
+ } elsif ( !$pid ) {
+ exec @_;
+ die "can't exec `". join(' ', @_) ."` program: $!";
+ } else {
+ return $pid;
+ }
+}
+
+sub process_in_file {
+ my $self = shift;
+ my %args = ( in => undef, options => undef, @_ );
+
+ my $text = RT::Test->file_content( $args{'in'} );
+ while ( my ($opt) = ($text =~ /\%\%(.+?)\%\%/) ) {
+ my $value = $args{'options'}{ lc $opt };
+ die "no value for $opt" unless defined $value;
+
+ $text =~ s/\%\%\Q$opt\E\%\%/$value/g;
+ }
+
+ my ($out_fh, $out_conf);
+ unless ( $args{'out'} ) {
+ ($out_fh, $out_conf) = tempfile();
+ } else {
+ $out_conf = $args{'out'};
+ open $out_fh, '>', $out_conf
+ or die "couldn't open '$out_conf': $!";
+ }
+ print $out_fh $text;
+ seek $out_fh, 0, 0;
+
+ return ($out_fh, $out_conf);
+}
+
+1;
commit 8fa6764471a147b98223e7245ca06fc38903ed17
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Thu Dec 9 17:07:50 2010 +0800
mention fcgi with other servers
diff --git a/docs/web_deployment.pod b/docs/web_deployment.pod
index 26a81c3..3209b22 100644
--- a/docs/web_deployment.pod
+++ b/docs/web_deployment.pod
@@ -200,5 +200,9 @@ Apache configuration file telling it about RT:
</Location>
</VirtualHost>
+To run RT using FastCGI with other web servers like nginx, please see
+L<Plack::Handler::FCGI> for configuration examples. Your should use
+C</opt/rt4/sbin/rt-server.fcgi> as your PSGI-app.
+
=cut
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list