[Rt-commit] rt branch, 4.2/auto-reload-config, created. rt-4.0.4-363-g7830286

? sunnavy sunnavy at bestpractical.com
Wed Jan 18 09:42:47 EST 2012


The branch, 4.2/auto-reload-config has been created
        at  783028677112f95397ff5112a5bde277d4f308a1 (commit)

- Log -----------------------------------------------------------------
commit 230b502ef7260fcee276101beaa712ed67725cf7
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jan 18 20:44:15 2012 +0800

    don't reload configs by Module::Refresh->refresh
    
    though configs are '.pm', they can't be simply reloaded like normal modules.
    see #19261

diff --git a/lib/RT.pm b/lib/RT.pm
index 92070b7..0f449a3 100644
--- a/lib/RT.pm
+++ b/lib/RT.pm
@@ -788,6 +788,22 @@ sub StyleSheets {
     return RT->Config->Get('CSSFiles');
 }
 
+=head2 RefreshModules
+
+Refresh modified modules except config.
+
+=cut
+
+sub RefreshModules {
+    require Module::Refresh;
+    my %config = Config->LoadedConfigs();
+
+    for my $mod ( keys %INC ) {
+        next if exists $config{$mod};
+        Module::Refresh->refresh_module_if_modified($mod);
+    }
+}
+
 =head1 BUGS
 
 Please report them to rt-bugs at bestpractical.com, if you know what's
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 5a94f27..8d17966 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1326,6 +1326,20 @@ sub UpdateOption {
     return 1;
 }
 
+=head2 LoadedConfigs
+
+Returns a hash of loaded config files, with filename as the key and path as
+the value.
+
+=cut
+
+sub LoadedConfigs {
+
+    my %config =
+      map { $_ => $INC{$_} } grep { /^\w+_(?:Site)?Config\.pm$/ } keys %INC;
+    return %config;
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index eefaab5..5fe4d66 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -211,9 +211,8 @@ sub WebExternalAutoInfo {
 sub HandleRequest {
     my $ARGS = shift;
 
-    if (RT->Config->Get('DevelMode')) {
-        require Module::Refresh;
-        Module::Refresh->refresh;
+    if ( RT->Config->Get('DevelMode') ) {
+        RT->RefreshModules;
     }
 
     $HTML::Mason::Commands::r->content_type("text/html; charset=utf-8");

commit 783028677112f95397ff5112a5bde277d4f308a1
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jan 18 20:48:40 2012 +0800

    restart server to reload configs
    
    most config items can be reloaded, but ones related to Plugins or Logs can
    not, and server won't change its port either even if $WebPort is changed.

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 8d17966..9bdb1cd 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1340,6 +1340,17 @@ sub LoadedConfigs {
     return %config;
 }
 
+=head2 UnloadConfigsFromINC
+
+Unload config files from %INC
+
+=cut
+
+sub UnloadConfigsFromINC {
+    my %config = LoadedConfigs();
+    delete $INC{$_} for keys %config;
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/sbin/rt-server.in b/sbin/rt-server.in
index b0e4dff..c1c05e2 100755
--- a/sbin/rt-server.in
+++ b/sbin/rt-server.in
@@ -209,6 +209,14 @@ else {
 push @args, '--server', 'Standalone' if RT->InstallMode;
 push @args, '--server', 'Starlet' unless $r->{server} || grep { m/--server/ } @args;
 
+if ( RT->Config->Get('DevelMode') ) {
+    my %config = RT->Config->LoadedConfigs();
+    push @args, '-R', join ',', values %config;
+
+    # unload here so we can reload them later
+    RT->Config->UnloadConfigsFromINC();
+}
+
 $r->parse_options(@args);
 
 delete $r->{options} if $is_fastcgi; ### mangle_host_port_socket ruins everything
@@ -222,7 +230,21 @@ unless ($r->{env} eq 'development') {
         print STDERR "$name: Accepting connections at $proto://$host:$args->{port}/\n";
     };
 }
-eval { $r->run($app) };
+
+if ( RT->Config->Get('DevelMode') ) {
+    eval {
+        $r->run(
+            sub {
+                RT->LoadConfig;
+                $app->(@_);
+            }
+        );
+    };
+}
+else {
+    eval { $r->run($app) };
+}
+
 if (my $err = $@) {
     handle_startup_error($err);
 }

-----------------------------------------------------------------------


More information about the Rt-commit mailing list