Changeset a55933e19f2f2e67eebba5b63eb7cd6dd671c2ec

Show
Ignore:
Timestamp:
05/21/08 21:29:29 (7 years ago)
Author:
Mark Harrison <mark@omniti.com>
git-committer:
Mark Harrison <mark@omniti.com> 1211405369 +0000
git-parent:

[c9675cb5dfd3dc82a465d4cdc92b6f861474561e]

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

Merging reloading code from markdevel to trunk.

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

Files:

Legend:

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

    r748aca8 ra55933e  
    33use strict; 
    44use Data::Dumper; 
     5use FileHandle; 
    56use UNIVERSAL qw/isa/; 
    67my %coderefs; 
     
    7576} 
    7677 
     78sub reload_module { 
     79    my $self = shift; 
     80    my $class = ref($self) || $self; 
     81    $class =~ s/::/\//g; 
     82    my $file = $INC{"$class.pm"}; 
     83    print STDERR "Reloading module: $class\n"; 
     84    my $fh = FileHandle->new($file); 
     85    local($/); 
     86    my $redef = 0; 
     87    local($SIG{__WARN__}) = sub { 
     88        if($_[0] =~ /[Ss]ubroutine ([\w:]+) redefined/ ) { 
     89            $redef++; 
     90            return; 
     91        } 
     92        warn @_; 
     93    }; 
     94    eval <$fh>; 
     95    return $@ if $@; 
     96    return $redef; 
     97} 
     98 
    7799$rmloading = "Demand loading"; 
    781001; 
  • resmon

    r1533dda ra55933e  
    3838 
    3939sub reconfigure { 
    40     print STDERR "Reloading...\n"; 
     40    my $modstatus = ""; 
     41    print STDERR "Reloading modules...\n"; 
     42    my $modules = $config->{Module}; 
     43    while ( my ($key, $value) = each(%$modules) ) { 
     44        my $mod = $value->[0]; # Only need the first of each module 
     45        my $errs = $mod->reload_module(); 
     46        if ($errs) { 
     47            my $modname = ref($mod) || $mod; 
     48            $modname =~ s/Resmon::Module:://; 
     49            $modstatus .= "$modname "; 
     50            print STDERR " Failed to reload module $modname\n"; 
     51            print STDERR $errs; 
     52            print STDERR " This module is no longer available.\n"; 
     53        } 
     54    } 
     55    print STDERR "Reloading configuration...\n"; 
    4156    eval { configure(); }; 
    4257    if ($@) { 
     58        # The config object is recreated every time we reload, so we shouldn't 
     59        # need to reset this BAD value to empty on a successful load. 
     60        $config->{'configstatus'} = "BAD"; 
    4361        print STDERR " Failed to reload: "; 
    4462        print STDERR $@; 
    4563        print STDERR " Continuing with old configuration\n"; 
    4664    } 
     65 
     66    $config->{'modstatus'} = $modstatus; 
    4767} 
    4868 
     
    99119      if($checkstat) { 
    100120        $results->{state} = 'BAD'; 
    101         $results->{message} = $checkstat
     121        $results->{message} = "Bad module or problem running handler code."
    102122      } else { 
    103123        $results->{state} = $check_rv;