X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Fsbin%2Frt-server.in;h=5b9fecd17bf73b283c3a4f1b7a8b604b17b7934a;hp=cd146e00a04e39610235fb78e0e675e810fabf6a;hb=HEAD;hpb=63a268637b2d51a8766412617724b9436439deb6 diff --git a/rt/sbin/rt-server.in b/rt/sbin/rt-server.in index cd146e00a..6069772d2 100644 --- a/rt/sbin/rt-server.in +++ b/rt/sbin/rt-server.in @@ -1,41 +1,41 @@ #!@PERL@ -w # BEGIN BPS TAGGED BLOCK {{{ -# +# # COPYRIGHT: -# -# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC -# -# +# +# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC +# +# # (Except where explicitly superseded by other copyright notices) -# -# +# +# # LICENSE: -# +# # This work is made available to you under the terms of Version 2 of # the GNU General Public License. A copy of that license should have # been provided with this software, but in any event can be snarfed # from www.gnu.org. -# +# # This work is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301 or visit their web page on the internet at # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. -# -# +# +# # CONTRIBUTION SUBMISSION POLICY: -# +# # (The following paragraph is not intended to limit the rights granted # to you to modify and distribute this software under the terms of # the GNU General Public License and is only of importance to you if # you choose to contribute your changes and enhancements to the # community by submitting them to Best Practical Solutions, LLC.) -# +# # By intentionally submitting any modifications, corrections or # derivatives to this work, or any other work intended for use with # Request Tracker, to Best Practical Solutions, LLC, you confirm that @@ -44,29 +44,29 @@ # royalty-free, perpetual, license to use, copy, create derivative # works based on those contributions, and sublicense and distribute # those contributions and any derivatives thereof. -# +# # END BPS TAGGED BLOCK }}} 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