2 # BEGIN BPS TAGGED BLOCK {{{
6 # This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
7 # <sales@bestpractical.com>
9 # (Except where explicitly superseded by other copyright notices)
14 # This work is made available to you under the terms of Version 2 of
15 # the GNU General Public License. A copy of that license should have
16 # been provided with this software, but in any event can be snarfed
19 # This work is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 # 02110-1301 or visit their web page on the internet at
28 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
31 # CONTRIBUTION SUBMISSION POLICY:
33 # (The following paragraph is not intended to limit the rights granted
34 # to you to modify and distribute this software under the terms of
35 # the GNU General Public License and is only of importance to you if
36 # you choose to contribute your changes and enhancements to the
37 # community by submitting them to Best Practical Solutions, LLC.)
39 # By intentionally submitting any modifications, corrections or
40 # derivatives to this work, or any other work intended for use with
41 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
42 # you are the copyright holder for those contributions and you grant
43 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
44 # royalty-free, perpetual, license to use, copy, create derivative
45 # works based on those contributions, and sublicense and distribute
46 # those contributions and any derivatives thereof.
48 # END BPS TAGGED BLOCK }}}
52 # fix lib paths, some may be relative
54 die <<EOT if ${^TAINT};
55 RT does not run under Perl's "taint mode". Remove -T from the command
56 line, or remove the PerlTaintCheck parameter from your mod_perl
61 my @libs = ("@RT_LIB_PATH@", "@LOCAL_LIB_PATH@");
65 unless ( File::Spec->file_name_is_absolute($lib) ) {
67 if ( File::Spec->file_name_is_absolute(__FILE__) ) {
68 $bin_path = ( File::Spec->splitpath(__FILE__) )[1];
73 $bin_path = $FindBin::Bin;
76 $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
86 if (grep { m/help/ } @ARGV) {
88 print Pod::Usage::pod2usage( { verbose => 2 } );
94 RT->InitPluginPaths();
96 require Module::Refresh if RT->Config->Get('DevelMode');
99 my ($integrity, $state, $msg) = RT::Handle->CheckIntegrity;
101 unless ( $integrity ) {
104 RT couldn't connect to the database where tickets are stored.
105 If this is a new installation of RT, you should visit the URL below
106 to configure RT and initialize your database.
108 If this is an existing RT installation, this may indicate a database
109 connectivity problem.
111 The error RT got back when trying to connect to your database was:
117 require RT::Installer;
118 # don't enter install mode if the file exists but is unwritable
119 if (-e RT::Installer->ConfigFile && !-w _) {
120 die 'Since your configuration exists ('
121 . RT::Installer->ConfigFile
122 . ") but is not writable, I'm refusing to do anything.\n";
125 RT->Config->Set( 'LexiconLanguages' => '*' );
130 RT->Init( Heavy => 1 );
132 my ($status, $msg) = RT::Handle->CheckCompatibility( $RT::Handle->dbh, 'post');
134 print STDERR $msg, "\n\n";
139 # we must disconnect DB before fork
141 $RT::Handle->dbh->disconnect if $RT::Handle->dbh;
142 $RT::Handle->dbh(undef);
146 require RT::Interface::Web::Handler;
147 my $app = RT::Interface::Web::Handler->PSGIApp;
149 if ($ENV{RT_TESTING}) {
150 my $screen_logger = $RT::Logger->remove('screen');
151 require Log::Dispatch::Perl;
153 Log::Dispatch::Perl->new(
155 min_level => $screen_logger->min_level,
162 require Plack::Middleware::Test::StashWarnings;
163 $app = Plack::Middleware::Test::StashWarnings->wrap($app);
166 # when used as a psgi file
172 # load appropriate server
174 require Plack::Runner;
176 my $is_fastcgi = $0 =~ m/fcgi$/;
177 my $r = Plack::Runner->new( $0 =~ /standalone/ ? ( server => 'Standalone' ) :
178 $is_fastcgi ? ( server => 'FCGI' )
180 env => 'deployment' );
182 # figure out the port
185 # handle "rt-server 8888" for back-compat, but complain about it
186 if ($ARGV[0] && $ARGV[0] =~ m/^\d+$/) {
187 warn "Deprecated: please run $0 --port $ARGV[0] instead\n";
188 unshift @ARGV, '--port';
193 use List::MoreUtils 'last_index';
194 my $last_index = last_index { $_ eq '--port' } @args;
198 if ( $last_index != -1 && $args[$last_index+1] =~ /^\d+$/ ) {
199 $explicit_port = $args[$last_index+1];
200 $port = $explicit_port;
202 # inform the rest of the system what port we manually chose
207 $env->{'rt.explicit_port'} = $port;
209 $old_app->($env, @_);
213 # default to the configured WebPort and inform Plack::Runner
214 $port = RT->Config->Get('WebPort') || '8080';
215 push @args, '--port', $port;
218 push @args, '--server', 'Standalone' if RT->InstallMode;
219 push @args, '--server', 'Starlet' unless $r->{server} || grep { m/--server/ } @args;
221 $r->parse_options(@args);
223 delete $r->{options} if $is_fastcgi; ### mangle_host_port_socket ruins everything
225 unless ($r->{env} eq 'development') {
226 push @{$r->{options}}, server_ready => sub {
228 my $name = $args->{server_software} || ref($args); # $args is $server
229 my $host = $args->{host} || 0;
230 my $proto = $args->{proto} || 'http';
231 print STDERR "$name: Accepting connections at $proto://$host:$args->{port}/\n";
234 eval { $r->run($app) };
236 handle_startup_error($err);
241 sub handle_startup_error {
243 if ( $err =~ /listen/ ) {
247 "Something went wrong while trying to run RT's standalone web server:\n\t"
253 sub handle_bind_error {
256 WARNING: RT couldn't start up a web server on port @{[$port]}.
257 This is often the case if the port is already in use or you're running @{[$0]}
258 as someone other than your system's "root" user. You may also specify a
259 temporary port with: $0 --port <port>
262 if ($explicit_port) {
264 "Please check your system configuration or choose another port\n\n";
272 rt-server - RT standalone server
276 # runs prefork server listening on port 8080, requires Starlet
277 rt-server --port 8080
279 # runs server listening on port 8080
280 rt-server --server Standalone --port 8080
282 standalone_httpd --port 8080
284 # runs other PSGI server on port 8080
285 rt-server --server Starman --port 8080