Changeset 1e192996f122a4915bf3fd4a5be4703e54437575

Show
Ignore:
Timestamp:
03/21/10 20:23:22 (5 years ago)
Author:
Mark Harrison <mark@omniti.com>
git-committer:
Mark Harrison <mark@omniti.com> 1269203002 +0000
git-parent:

[ad00dabd881e008eca268126c2b47adb63274e58]

git-author:
Mark Harrison <mark@omniti.com> 1269203002 +0000
Message:

Module reloading code (reloads on HUP)

This is much simpler than the previous version, reusing the configure class. I
think the previous version failed because entries have to be deleted from %INC
before being reloaded.

Warnings are still printed saying functionname redefined. This can be fixed
with "no warnings 'redefine';" in each module, but it would be nice to not
require module writers to have to do that. There is probably a way to set that
when loading the module from Config.pm.

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@278 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/Resmon/Config.pm

    r437d7c1 r1e19299  
    5353            if(/\s*(\S+)\s*\{/) { 
    5454                $current = $1; 
     55 
     56                # Delete the module from %INC if it exists. This will reload 
     57                # any module if needed. 
     58                my $mod_filename = "$current.pm"; 
     59                $mod_filename =~ s/::/\//g; 
     60                delete $INC{$mod_filename}; 
     61 
    5562                eval "use $current;"; 
    5663                if ($@) { 
  • resmon

    ra1fc8c1 r1e19299  
    4545 
    4646configure(); 
     47 
     48my $sighup = 0; 
     49sub sighup_handler { $sighup = 1; } 
     50$SIG{'HUP'} = \&sighup_handler; 
    4751 
    4852my $sigint = 0; 
     
    124128    $status->close(); 
    125129    die "Exiting.\n" if($sigint); 
    126     reap_zombies(); 
    127     wait_interval(); 
    128     reap_zombies(); 
     130    if ($sighup) { 
     131        # Reload configuration (and modules) on SIGHUP 
     132        $sighup = 0; 
     133        print STDERR "Reloading modules\n"; 
     134        $config = Resmon::Config->new($config_file); 
     135    } else { 
     136        reap_zombies(); 
     137        wait_interval(); 
     138        reap_zombies(); 
     139    } 
    129140    die "Exiting.\n" if($sigint); 
    130141    print "\n---- ".localtime(time)."----------\n"