[Rt-commit] r13115 - in rt/branches/3.8-TESTING: bin lib/RT/Interface/Web
jesse at bestpractical.com
jesse at bestpractical.com
Tue Jun 10 13:08:28 EDT 2008
Author: jesse
Date: Tue Jun 10 13:08:28 2008
New Revision: 13115
Modified:
rt/branches/3.8-TESTING/ (props changed)
rt/branches/3.8-TESTING/bin/standalone_httpd.in
rt/branches/3.8-TESTING/lib/RT/Interface/Web/Standalone.pm
Log:
r32571 at 31b: jesse | 2008-06-10 13:08:11 -0400
standalone_httpd friendlyness improvements
Modified: rt/branches/3.8-TESTING/bin/standalone_httpd.in
==============================================================================
--- rt/branches/3.8-TESTING/bin/standalone_httpd.in (original)
+++ rt/branches/3.8-TESTING/bin/standalone_httpd.in Tue Jun 10 13:08:28 2008
@@ -81,7 +81,8 @@
RT::CheckPerlRequirements();
-my $port = shift @ARGV || RT->Config->Get('WebPort') || '8080';
+my $explicit_port = shift @ARGV;
+my $port = $explicit_port || RT->Config->Get('WebPort') || '8080';
require RT::Handle;
@@ -117,24 +118,56 @@
RT->InitPlugins();
}
+
+
require RT::Interface::Web::Standalone;
my $server = RT::Interface::Web::Standalone->new;
-$server->port($port);
-eval { $server->run() };
+run_server($port);
+exit 0;
-if (my $err = $@) {
- if ($err =~ /bind: Permission denied/ && $port <= 1024) {
- print STDERR <<EOF;
-RT couldn't start up a web server on port @{[$port]}. This is often the case
-if you're running @{[$0]} as someone other than your
-system's "root" user.
+sub run_server {
+ my $port = shift;
+ $server->port($port);
+ eval { $server->run() };
-For now, RT has picked a random alternate port to run on.
-EOF
- $server->port( 8000 + int(rand(1024))) ;
- $server->run;
- } else {
- die $err;
- }
+ if ( my $err = $@ ) {
+ handle_startup_error($err);
+ }
}
+sub handle_startup_error {
+ my $err = shift;
+ if ( $err =~ /bind: Permission denied/ ) {
+ handle_bind_error();
+ } else {
+ die
+ "Something went wrong while trying to run RT's standalone web server:\n\t"
+ . $err;
+ }
+}
+
+
+sub handle_bind_error {
+
+ print STDERR <<EOF;
+WARNINING: RT couldn't start up a web server on port @{[$port]}.
+This is often the case if you're running @{[$0]} as
+someone other than your system's "root" user.
+EOF
+
+ if ($explicit_port) {
+ print STDERR
+ "Please check your system configuration or choose another port\n\n";
+ } else {
+ print STDERR "\nFor now, RT has chosen an alternate port to run on.\n\n";
+ if ( !$integrity ) {
+ print STDERR <<EOF;
+You can use this server to configure and explore RT. While configuring
+RT, you'll have a chance to set a permanent port and URL for your
+server.
+
+EOF
+ }
+ run_server( 8000 + int( rand(1024) ) );
+ }
+}
Modified: rt/branches/3.8-TESTING/lib/RT/Interface/Web/Standalone.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/Interface/Web/Standalone.pm (original)
+++ rt/branches/3.8-TESTING/lib/RT/Interface/Web/Standalone.pm Tue Jun 10 13:08:28 2008
@@ -53,6 +53,7 @@
use base 'HTTP::Server::Simple::Mason';
use RT::Interface::Web::Handler;
use RT::Interface::Web;
+use URI;
sub handler_class { "RT::Interface::Web::Handler" }
@@ -88,4 +89,29 @@
return $self->{rt_net_server};
}
+
+=head2 print_banner
+
+This routine prints a banner before the server request-handling loop
+starts.
+
+Methods below this point are probably not terribly useful to define
+yourself in subclasses.
+
+=cut
+
+sub print_banner {
+ my $self = shift;
+
+ my $url = URI->new( RT->Config->Get('WebBaseURL'));
+ $url->host('127.0.0.1') if ($url->host() eq 'localhost');
+ $url->port($self->port);
+ print(
+ "You can connect to your server at "
+ . $url->canonical
+ . "\n" );
+
+}
+
+
1;
More information about the Rt-commit
mailing list