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

Merging reloading code from markdevel to trunk.

git-svn-id: https://labs.omniti.com/resmon/trunk@106 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
parent c9675cb5
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package Resmon::Module;
use strict;
use Data::Dumper;
use FileHandle;
use UNIVERSAL qw/isa/;
my %coderefs;
......@@ -74,5 +75,26 @@ sub config_as_hash {
return $conf;
}
sub reload_module {
my $self = shift;
my $class = ref($self) || $self;
$class =~ s/::/\//g;
my $file = $INC{"$class.pm"};
print STDERR "Reloading module: $class\n";
my $fh = FileHandle->new($file);
local($/);
my $redef = 0;
local($SIG{__WARN__}) = sub {
if($_[0] =~ /[Ss]ubroutine ([\w:]+) redefined/ ) {
$redef++;
return;
}
warn @_;
};
eval <$fh>;
return $@ if $@;
return $redef;
}
$rmloading = "Demand loading";
1;
......@@ -37,13 +37,33 @@ sub configure {
}
sub reconfigure {
print STDERR "Reloading...\n";
my $modstatus = "";
print STDERR "Reloading modules...\n";
my $modules = $config->{Module};
while ( my ($key, $value) = each(%$modules) ) {
my $mod = $value->[0]; # Only need the first of each module
my $errs = $mod->reload_module();
if ($errs) {
my $modname = ref($mod) || $mod;
$modname =~ s/Resmon::Module:://;
$modstatus .= "$modname ";
print STDERR " Failed to reload module $modname\n";
print STDERR $errs;
print STDERR " This module is no longer available.\n";
}
}
print STDERR "Reloading configuration...\n";
eval { configure(); };
if ($@) {
# The config object is recreated every time we reload, so we shouldn't
# need to reset this BAD value to empty on a successful load.
$config->{'configstatus'} = "BAD";
print STDERR " Failed to reload: ";
print STDERR $@;
print STDERR " Continuing with old configuration\n";
}
$config->{'modstatus'} = $modstatus;
}
$SIG{'HUP'} = \&reconfigure;
......@@ -98,7 +118,7 @@ while(1) {
};
if($checkstat) {
$results->{state} = 'BAD';
$results->{message} = $checkstat;
$results->{message} = "Bad module or problem running handler code.";
} else {
$results->{state} = $check_rv;
$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