-
Mark Harrison authored
Adding reload support to the resmon init script, and changed the web server child process to ignore the HUP signal so killproc -HUP (and killall -HUP) will work correctly. git-svn-id: https://labs.omniti.com/resmon/trunk@117 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
Mark Harrison authoredAdding reload support to the resmon init script, and changed the web server child process to ignore the HUP signal so killproc -HUP (and killall -HUP) will work correctly. git-svn-id: https://labs.omniti.com/resmon/trunk@117 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Status.pm 12.47 KiB
package Resmon::Status;
use strict;
use POSIX qw/:sys_wait_h/;
use IO::Handle;
use IO::File;
use IO::Socket;
use Socket;
use Fcntl qw/:flock/;
use IPC::SysV qw /IPC_PRIVATE IPC_CREAT IPC_RMID ftok S_IRWXU S_IRWXG S_IRWXO/;
use Data::Dumper;
my $SEGSIZE = 1024*256;
my $KEEPALIVE_TIMEOUT = 5;
my $REQUEST_TIMEOUT = 60;
sub new {
my $class = shift;
my $file = shift;
return bless {
file => $file
}, $class;
}
sub get_shared_state {
my $self = shift;
my $blob;
my $len;
return unless(defined($self->{shared_state}));
# Lock shared segment
# Read in
shmread($self->{shared_state}, $len, 0, length(pack('i', 0)));
$len = unpack('i', $len);
shmread($self->{shared_state}, $blob, length(pack('i', 0)), $len);
# unlock
my $VAR1;
eval $blob;
die $@ if ($@);
$self->{store} = $VAR1;
return $self->{store};
}
sub store_shared_state {
my $self = shift;
return unless(defined($self->{shared_state}));
my $blob = Dumper($self->{store});
# Lock shared segment
# Write state and flush
shmwrite($self->{shared_state}, pack('i', length($blob)),
0, length(pack('i', 0))) || die "$!";
shmwrite($self->{shared_state}, $blob, length(pack('i', 0)),
length($blob)) || die "$!";
# unlock
}
sub xml_kv_dump {
my $info = shift;
my $indent = shift || 0;
my $rv = '';
while(my ($key, $value) = each %$info) {
$rv .= " " x $indent;
if(ref $value eq 'HASH') {
$rv .= "<$key>\n";
$rv .= xml_kv_dump($value, $indent + 2);
$rv .= " " x $indent;
$rv .= "</$key>\n";
}
else {
$value =~ s/&/&/g;
$value =~ s/</</g;
$value =~ s/>/>/g;
$value =~ s/'/'/g;
$rv .= "<$key>$value</$key>\n";