Przeglądaj źródła

Remove missing conf param, leave notes for future

Also HUP the server correctly based on server
George Baugh 2 lat temu
rodzic
commit
05cf835ce3
6 zmienionych plików z 24 dodań i 14 usunięć
  1. 3 0
      lib/TCMS.pm
  2. 2 5
      lib/Trog/DataModule.pm
  3. 12 7
      lib/Trog/Routes/HTML.pm
  4. 4 2
      lib/Trog/Utils.pm
  5. 1 0
      tcms
  6. 2 0
      www/server.psgi

+ 3 - 0
lib/TCMS.pm

@@ -39,6 +39,9 @@ use Trog::FileHandler;
 
 # Troglodyne philosophy - simple as possible
 
+# What PSGI server are we running as?  We set this in each runner.
+my $engine = $ENV{PSGI_ENGINE};
+
 # Import the routes
 my $conf  = Trog::Config::get();
 my $data  = Trog::Data->new($conf);

+ 2 - 5
lib/Trog/DataModule.pm

@@ -288,11 +288,8 @@ sub add ( $self, @posts ) {
     }
     $self->write( \@to_write );
 
-    #hup the parent to refresh the routing table IFF we aren't in an interactive session, such as migrate.pl
-    if ( !$ENV{NOHUP} ) {
-        my $parent = getppid;
-        kill 'HUP', $parent;
-    }
+    #hup the parent to refresh the routing table
+    Trog::Utils::restart_parent();
 
     # Gorilla cache invalidation
     Path::Tiny::path('www/statics')->remove_tree;

+ 12 - 7
lib/Trog/Routes/HTML.pm

@@ -640,12 +640,19 @@ Renders the configuration page, or redirects you back to the login page.
 
 =cut
 
-sub config ($query) {
+sub config ($query={}) {
     return see_also('/login')                    unless $query->{user};
     return Trog::Routes::HTML::forbidden($query) unless grep { $_ eq 'admin' } @{ $query->{user_acls} };
 
     $query->{failure} //= -1;
 
+    #XXX ACHTUNG config::simple has this brain damaged behavior of returning a multiple element array when you access something that does not exist.
+    #XXX straight up dying would be preferrable.
+    #XXX anyways, this means you can NEVER NEVER NEVER access a param from within a hash directly.  YOU HAVE BEEN WARNED!
+    my $theme  = $conf->param('general.theme') // '';
+    my $dm     = $conf->param('general.data_model') // 'DUMMY';
+    my $embeds = $conf->param('security.allow_embeds_from') // '';
+
     return Trog::Routes::HTML::index(
         {
             title              => 'Configure tCMS',
@@ -654,14 +661,13 @@ sub config ($query) {
             scripts            => [qw{post.js}],
             themes             => _get_themes() || [],
             data_models        => _get_data_models(),
-            current_theme      => $conf->param('general.theme')      // '',
-            current_data_model => $conf->param('general.data_model') // 'DUMMY',
-            totp_secret        => $conf->param('totp.secret'),
+            current_theme      => $theme,
+            current_data_model => $dm,
             message            => $query->{message},
             failure            => $query->{failure},
             to                 => '/config',
             scheme             => $query->{scheme},
-            embeds             => $conf->param('security.allow_embeds_from') // '',
+            embeds             => $embeds,
             is_admin           => 1,
             template           => 'config.tx',
             %$query,
@@ -799,8 +805,7 @@ sub config_save ($query) {
     }
 
     #Get the PID of the parent port using lsof, send HUP
-    my $parent = getppid;
-    kill 'HUP', $parent;
+    Trog::Utils::restart_parent();
 
     return config($query);
 }

+ 4 - 2
lib/Trog/Utils.pm

@@ -25,8 +25,10 @@ sub strip_and_trunc ($s) {
 }
 
 # Instruct the parent to restart.  Normally this is HUP, but nginx-unit decides to be special.
-sub restart_parent ( $env ) {
-    if ($env->{PSGI_ENGINE} && $env->{PSGI_ENGINE} eq 'nginx-unit') {
+# Don't do anything if running NOHUP=1, which is useful when doing bulk operations
+sub restart_parent {
+    return if $ENV{NOHUP};
+    if ($ENV{PSGI_ENGINE} && $ENV{PSGI_ENGINE} eq 'nginx-unit') {
         my $conf = Trog::Config->get();
         my $nginx_socket = $conf->param('nginx-unit.socket');
         my $client = HTTP::Tiny::UNIX->new();

+ 1 - 0
tcms

@@ -1,2 +1,3 @@
 #!/bin/bash
+export PSGI_ENGINE='uwsgi'
 uwsgi --ini config/tcms.ini

+ 2 - 0
www/server.psgi

@@ -7,4 +7,6 @@ use warnings;
 use lib 'lib';
 use TCMS;
 
+$ENV{PSGI_ENGINE} //= 'starman';
+
 our $app = \&TCMS::app;