Changeset 1533dda22b2e7854c9d23a7dc3df5b57e838e66f

Show
Ignore:
Timestamp:
05/14/08 18:53:52 (7 years ago)
Author:
Mark Harrison <mark@omniti.com>
git-committer:
Mark Harrison <mark@omniti.com> 1210791232 +0000
git-parent:

[36631e9cdfacbfd046a989336974b1af1982f9e3]

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

Resmon no longer dies on config file errors on reload. Also show a better
error message when starting with a faulty module.

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

Files:

Legend:

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

    r37857c4 r1533dda  
    2626        my $object = bless \%kvs, "Resmon::Module::$current"; 
    2727        push(@{$self->{Module}->{$current}}, $object); 
     28 
     29        # Test to make sure the module actually works 
     30        my $coderef; 
     31        eval { $coderef = Resmon::Module::fetch_monitor($current); }; 
     32        if (!$coderef) { 
     33                # Try to execute the config_as_hash method. If it fails, then 
     34                # the module didn't load properly (e.g. syntax error). 
     35                eval { $object->config_as_hash; }; 
     36                die "Problem loading module $current" if $@; 
     37        } else { 
     38            print STDERR "moo"; 
     39        } 
     40 
    2841      } elsif (/^\s*\}\s*$/) { 
    2942        $current = undef; 
  • resmon

    r0eea370 r1533dda  
    3737} 
    3838 
    39 $SIG{'HUP'} = \&configure; 
     39sub reconfigure { 
     40    print STDERR "Reloading...\n"; 
     41    eval { configure(); }; 
     42    if ($@) { 
     43        print STDERR " Failed to reload: "; 
     44        print STDERR $@; 
     45        print STDERR " Continuing with old configuration\n"; 
     46    } 
     47
     48 
     49$SIG{'HUP'} = \&reconfigure; 
    4050configure(); 
    4151 
     
    8292        eval { ($check_rv, $check_mess) = $monobj->handler(); }; 
    8393      } 
     94      my $checkstat = $@; 
    8495      my $results = { 
    8596        configuration => eval { $monobj->config_as_hash(); }, 
    8697        last_runtime_seconds => sprintf("%.6f", tv_interval($starttime)), 
    8798      }; 
    88       if($@) { 
     99      if($checkstat) { 
    89100        $results->{state} = 'BAD'; 
    90         $results->{message} = $@
     101        $results->{message} = $checkstat
    91102      } else { 
    92103        $results->{state} = $check_rv;