X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Fsbin%2Frt-server.in;h=5b9fecd17bf73b283c3a4f1b7a8b604b17b7934a;hp=bf6da6e580ac134a8839e969a66ef7c664ecf4fd;hb=HEAD;hpb=fc6209f398899f0211cfcedeb81a3cd65e04a941 diff --git a/rt/sbin/rt-server.in b/rt/sbin/rt-server.in index bf6da6e58..6069772d2 100644 --- a/rt/sbin/rt-server.in +++ b/rt/sbin/rt-server.in @@ -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 # # # (Except where explicitly superseded by other copyright notices) @@ -49,24 +49,24 @@ use warnings; use strict; -# fix lib paths, some may be relative BEGIN { + die <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 <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