Skip to content
Snippets Groups Projects
Commit 1533dda2 authored by Mark Harrison's avatar Mark Harrison
Browse files

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
parent 36631e9c
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,19 @@ sub new { ...@@ -25,6 +25,19 @@ sub new {
grep { $kvs{$1} = $2 if /^\s*(\S+)\s*=>\s*(\S+)\s*$/ } @params; grep { $kvs{$1} = $2 if /^\s*(\S+)\s*=>\s*(\S+)\s*$/ } @params;
my $object = bless \%kvs, "Resmon::Module::$current"; my $object = bless \%kvs, "Resmon::Module::$current";
push(@{$self->{Module}->{$current}}, $object); push(@{$self->{Module}->{$current}}, $object);
# Test to make sure the module actually works
my $coderef;
eval { $coderef = Resmon::Module::fetch_monitor($current); };
if (!$coderef) {
# Try to execute the config_as_hash method. If it fails, then
# the module didn't load properly (e.g. syntax error).
eval { $object->config_as_hash; };
die "Problem loading module $current" if $@;
} else {
print STDERR "moo";
}
} elsif (/^\s*\}\s*$/) { } elsif (/^\s*\}\s*$/) {
$current = undef; $current = undef;
} else { } else {
......
...@@ -36,7 +36,17 @@ sub configure { ...@@ -36,7 +36,17 @@ sub configure {
$config->{interface} = $interface if($interface); $config->{interface} = $interface if($interface);
} }
$SIG{'HUP'} = \&configure; sub reconfigure {
print STDERR "Reloading...\n";
eval { configure(); };
if ($@) {
print STDERR " Failed to reload: ";
print STDERR $@;
print STDERR " Continuing with old configuration\n";
}
}
$SIG{'HUP'} = \&reconfigure;
configure(); configure();
my $sigint = 0; my $sigint = 0;
...@@ -81,13 +91,14 @@ while(1) { ...@@ -81,13 +91,14 @@ while(1) {
} else { } else {
eval { ($check_rv, $check_mess) = $monobj->handler(); }; eval { ($check_rv, $check_mess) = $monobj->handler(); };
} }
my $checkstat = $@;
my $results = { my $results = {
configuration => eval { $monobj->config_as_hash(); }, configuration => eval { $monobj->config_as_hash(); },
last_runtime_seconds => sprintf("%.6f", tv_interval($starttime)), last_runtime_seconds => sprintf("%.6f", tv_interval($starttime)),
}; };
if($@) { if($checkstat) {
$results->{state} = 'BAD'; $results->{state} = 'BAD';
$results->{message} = $@; $results->{message} = $checkstat;
} else { } else {
$results->{state} = $check_rv; $results->{state} = $check_rv;
$results->{message} = $check_mess; $results->{message} = $check_mess;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment