Changeset 1e192996f122a4915bf3fd4a5be4703e54437575
- Timestamp:
- 03/21/10 20:23:22
(3 years ago)
- Author:
- Mark Harrison <mark@omniti.com>
- git-committer:
- Mark Harrison <mark@omniti.com> 1269203002 +0000
- git-parent:
[ad00dabd881e008eca268126c2b47adb63274e58]
- git-author:
- Mark Harrison <mark@omniti.com> 1269203002 +0000
- Message:
Module reloading code (reloads on HUP)
This is much simpler than the previous version, reusing the configure class. I
think the previous version failed because entries have to be deleted from %INC
before being reloaded.
Warnings are still printed saying functionname redefined. This can be fixed
with "no warnings 'redefine';" in each module, but it would be nice to not
require module writers to have to do that. There is probably a way to set that
when loading the module from Config.pm.
git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@278 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r437d7c1 |
r1e19299 |
|
| 53 | 53 | if(/\s*(\S+)\s*\{/) { |
|---|
| 54 | 54 | $current = $1; |
|---|
| | 55 | |
|---|
| | 56 | # Delete the module from %INC if it exists. This will reload |
|---|
| | 57 | # any module if needed. |
|---|
| | 58 | my $mod_filename = "$current.pm"; |
|---|
| | 59 | $mod_filename =~ s/::/\//g; |
|---|
| | 60 | delete $INC{$mod_filename}; |
|---|
| | 61 | |
|---|
| 55 | 62 | eval "use $current;"; |
|---|
| 56 | 63 | if ($@) { |
|---|
| ra1fc8c1 |
r1e19299 |
|
| 45 | 45 | |
|---|
| 46 | 46 | configure(); |
|---|
| | 47 | |
|---|
| | 48 | my $sighup = 0; |
|---|
| | 49 | sub sighup_handler { $sighup = 1; } |
|---|
| | 50 | $SIG{'HUP'} = \&sighup_handler; |
|---|
| 47 | 51 | |
|---|
| 48 | 52 | my $sigint = 0; |
|---|
| … | … | |
| 124 | 128 | $status->close(); |
|---|
| 125 | 129 | die "Exiting.\n" if($sigint); |
|---|
| 126 | | reap_zombies(); |
|---|
| 127 | | wait_interval(); |
|---|
| 128 | | reap_zombies(); |
|---|
| | 130 | if ($sighup) { |
|---|
| | 131 | # Reload configuration (and modules) on SIGHUP |
|---|
| | 132 | $sighup = 0; |
|---|
| | 133 | print STDERR "Reloading modules\n"; |
|---|
| | 134 | $config = Resmon::Config->new($config_file); |
|---|
| | 135 | } else { |
|---|
| | 136 | reap_zombies(); |
|---|
| | 137 | wait_interval(); |
|---|
| | 138 | reap_zombies(); |
|---|
| | 139 | } |
|---|
| 129 | 140 | die "Exiting.\n" if($sigint); |
|---|
| 130 | 141 | print "\n---- ".localtime(time)."----------\n" |
|---|