Changeset a55933e19f2f2e67eebba5b63eb7cd6dd671c2ec
- Timestamp:
- 05/21/08 21:29:29
(5 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
| r748aca8 |
ra55933e |
|
| 3 | 3 | use strict; |
|---|
| 4 | 4 | use Data::Dumper; |
|---|
| | 5 | use FileHandle; |
|---|
| 5 | 6 | use UNIVERSAL qw/isa/; |
|---|
| 6 | 7 | my %coderefs; |
|---|
| … | … | |
| 75 | 76 | } |
|---|
| 76 | 77 | |
|---|
| | 78 | sub 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 | |
|---|
| 77 | 99 | $rmloading = "Demand loading"; |
|---|
| 78 | 100 | 1; |
|---|
| r1533dda |
ra55933e |
|
| 38 | 38 | |
|---|
| 39 | 39 | sub 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"; |
|---|
| 41 | 56 | eval { configure(); }; |
|---|
| 42 | 57 | 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"; |
|---|
| 43 | 61 | print STDERR " Failed to reload: "; |
|---|
| 44 | 62 | print STDERR $@; |
|---|
| 45 | 63 | print STDERR " Continuing with old configuration\n"; |
|---|
| 46 | 64 | } |
|---|
| | 65 | |
|---|
| | 66 | $config->{'modstatus'} = $modstatus; |
|---|
| 47 | 67 | } |
|---|
| 48 | 68 | |
|---|
| … | … | |
| 99 | 119 | if($checkstat) { |
|---|
| 100 | 120 | $results->{state} = 'BAD'; |
|---|
| 101 | | $results->{message} = $checkstat; |
|---|
| | 121 | $results->{message} = "Bad module or problem running handler code."; |
|---|
| 102 | 122 | } else { |
|---|
| 103 | 123 | $results->{state} = $check_rv; |
|---|