default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / rt / sbin / rt-server.in
index bf6da6e..6069772 100644 (file)
@@ -3,7 +3,7 @@
 #
 # COPYRIGHT:
 #
-# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC
 #                                          <sales@bestpractical.com>
 #
 # (Except where explicitly superseded by other copyright notices)
 use warnings;
 use strict;
 
-# fix lib paths, some may be relative
 BEGIN {
+    die <<EOT if ${^TAINT};
+RT does not run under Perl's "taint mode".  Remove -T from the command
+line, or remove the PerlTaintCheck parameter from your mod_perl
+configuration.
+EOT
+}
+
+# fix lib paths, some may be relative
+BEGIN { # BEGIN RT CMD BOILERPLATE
     require File::Spec;
+    require Cwd;
     my @libs = ("@RT_LIB_PATH@", "@LOCAL_LIB_PATH@");
     my $bin_path;
 
     for my $lib (@libs) {
         unless ( File::Spec->file_name_is_absolute($lib) ) {
-            unless ($bin_path) {
-                if ( File::Spec->file_name_is_absolute(__FILE__) ) {
-                    $bin_path = ( File::Spec->splitpath(__FILE__) )[1];
-                }
-                else {
-                    require FindBin;
-                    no warnings "once";
-                    $bin_path = $FindBin::Bin;
-                }
-            }
+            $bin_path ||= ( File::Spec->splitpath(Cwd::abs_path(__FILE__)) )[1];
             $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
         }
         unshift @INC, $lib;
@@ -74,23 +74,29 @@ BEGIN {
 
 }
 
-use RT;
-RT::LoadConfig();
-RT->InitLogging();
-if (RT->Config->Get('DevelMode')) { require Module::Refresh; }
+use Getopt::Long;
+no warnings 'once';
 
-RT::CheckPerlRequirements();
-RT->InitPluginPaths();
+if (grep { m/help/ } @ARGV) {
+    require Pod::Usage;
+    print Pod::Usage::pod2usage( { verbose => 2 } );
+    exit;
+}
 
-my $port = shift @ARGV || RT->Config->Get('WebPort') || '8080';
+require RT;
+die "Wrong version of RT $RT::VERSION found; need @RT_VERSION_MAJOR@.@RT_VERSION_MINOR@.*"
+    unless $RT::VERSION =~ /^@RT_VERSION_MAJOR@\.@RT_VERSION_MINOR@\./;
 
+RT->LoadConfig();
+RT->InitPluginPaths();
+RT->InitLogging();
 
 require RT::Handle;
 my ($integrity, $state, $msg) = RT::Handle->CheckIntegrity;
 
 unless ( $integrity ) {
     print STDERR <<EOF;
-    
+
 RT couldn't connect to the database where tickets are stored.
 If this is a new installation of RT, you should visit the URL below
 to configure RT and initialize your database.
@@ -107,7 +113,9 @@ EOF
     require RT::Installer;
     # don't enter install mode if the file exists but is unwritable
     if (-e RT::Installer->ConfigFile && !-w _) {
-        die "Since your configuration exists but is not writable, I'm refusing to do anything.\n";
+        die 'Since your configuration exists ('
+          . RT::Installer->ConfigFile
+          . ") but is not writable, I'm refusing to do anything.\n";
     }
 
     RT->Config->Set( 'LexiconLanguages' => '*' );
@@ -115,15 +123,59 @@ EOF
 
     RT->InstallMode(1);
 } else {
-    RT->ConnectToDatabase();
-    RT->InitSystemObjects();
-    RT->InitClasses();
-    RT->InitPlugins();
+    RT->Init( Heavy => 1 );
+
+    my ($status, $msg) = RT::Handle->CheckCompatibility( $RT::Handle->dbh, 'post');
+    unless ( $status ) {
+        print STDERR $msg, "\n\n";
+        exit -1;
+    }
 }
 
-require RT::Interface::Web::Standalone;
-my $server = RT::Interface::Web::Standalone->new;
-$server->net_server('RT::Interface::Web::Standalone::PreFork');
-$server->port($port);
-$server->run();
+# we must disconnect DB before fork
+if ($RT::Handle) {
+    $RT::Handle->dbh->disconnect if $RT::Handle->dbh;
+    $RT::Handle->dbh(undef);
+    undef $RT::Handle;
+}
+
+require RT::PlackRunner;
+# when used as a psgi file
+if (caller) {
+    return RT::PlackRunner->app;
+}
+
+
+my $r = RT::PlackRunner->new( RT->InstallMode    ? ( server => 'Standalone' ) :
+                              $0 =~ /standalone/ ? ( server => 'Standalone' ) :
+                              $0 =~ /fcgi$/      ? ( server => 'FCGI',    env => "deployment" )
+                                                 : ( server => 'Starlet', env => "deployment" ) );
+$r->parse_options(@ARGV);
+
+# Try to clean up wrong-permissions var/
+$SIG{INT} = sub {
+    local $@;
+    system("chown", "-R", "@WEB_USER@:@WEB_GROUP@", "@RT_VAR_PATH_R@");
+    exit 0;
+} if $> == 0;
+
+$r->run;
+
+__END__
+
+=head1 NAME
+
+rt-server - RT standalone server
+
+=head1 SYNOPSIS
+
+    # runs prefork server listening on port 8080, requires Starlet
+    rt-server --port 8080
+
+    # runs server listening on port 8080
+    rt-server --server Standalone --port 8080
+    # or
+    standalone_httpd --port 8080
 
+    # runs other PSGI server on port 8080
+    rt-server --server Starman --port 8080