1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
6 # <sales@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
52 package RT::PlackRunner;
54 use base 'Plack::Runner';
58 return $class->SUPER::new( default_middleware => 0, @_ );
64 # handle "rt-server 8888" for back-compat, but complain about it
65 if (@args && $args[0] =~ m/^\d+$/) {
66 warn "Deprecated: please run $0 --port $ARGV[0] instead\n";
67 unshift @args, '--port';
70 $self->SUPER::parse_options(@args);
72 $self->{app} ||= $self->app;
73 $self->{server} ||= $self->loader->guess;
75 my %args = @{$self->{options}};
76 if ($self->{server} eq "FCGI") {
77 # We deal with the possible failure modes of this in ->run
78 } elsif ($args{port}) {
79 $self->{explicit_port} = 1;
80 my $old_app = $self->{app};
83 $env->{'rt.explicit_port'} = $args{port};
87 $self->set_options(port => (RT->Config->Get('WebPort') || '8080'));
91 # Don't assume port 5000 with no port or socket supplied; this allows
92 # the WebPort default to kick in (above), and also to provide useful
93 # error messages when starting FCGI without any options.
94 sub mangle_host_port_socket {
96 my ($host, $port, $socket, @listen) = @_;
97 return $self->SUPER::mangle_host_port_socket(@_)
98 if @listen or $port or $socket;
100 return host => $host, port => $port, socket => $socket,
101 @listen ? (listen => \@listen) : ();
105 require RT::Interface::Web::Handler;
106 my $app = RT::Interface::Web::Handler->PSGIApp;
108 if ($ENV{RT_TESTING}) {
109 my $screen_logger = $RT::Logger->remove('screen');
110 require Log::Dispatch::Perl;
112 Log::Dispatch::Perl->new(
114 min_level => $screen_logger->min_level,
121 require Plack::Middleware::Test::StashWarnings;
122 $app = Plack::Middleware::Test::StashWarnings->wrap($app);
131 my %args = @{$self->{options}};
133 # Plack::Handler::FCGI has its own catch for this, but doesn't
134 # notice that listen is an empty list, and we can also provide a
135 # better error message.
136 if ($self->{server} eq "FCGI" and not -S STDIN and not @{$args{listen} || []}) {
137 print STDERR "STDIN is not a socket, and no --listen, --socket, or --port provided\n";
141 eval { $self->SUPER::run(@_) };
145 if ( $err =~ /listen/ ) {
147 WARNING: RT couldn't start up a web server on port $args{port}.
148 This is often the case if the port is already in use or you're running @{[$0]}
149 as someone other than your system's "root" user. You may also specify a
150 temporary port with: $0 --port <port>
153 if ($self->{explicit_port}) {
155 "Please check your system configuration or choose another port\n\n";
160 "Something went wrong while trying to run RT's standalone web server:\n\t"