-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