Only load SYs::MemInfo and Sys::CpuLoad if we are going to use them. Only start various services if they are turned on
parent
146d56a6a0
commit
cdbe1b9216
|
@ -69,8 +69,6 @@ use POSIX;
|
||||||
use Socket;
|
use Socket;
|
||||||
use IO::Handle;
|
use IO::Handle;
|
||||||
use Time::HiRes qw(usleep);
|
use Time::HiRes qw(usleep);
|
||||||
use Sys::MemInfo qw(totalmem freemem totalswap freeswap);
|
|
||||||
use Sys::CpuLoad;
|
|
||||||
|
|
||||||
use autouse 'Pod::Usage'=>qw(pod2usage);
|
use autouse 'Pod::Usage'=>qw(pod2usage);
|
||||||
#use Data::Dumper;
|
#use Data::Dumper;
|
||||||
|
@ -101,6 +99,7 @@ my @daemons = (
|
||||||
'zmx10.pl',
|
'zmx10.pl',
|
||||||
'zmwatch.pl',
|
'zmwatch.pl',
|
||||||
'zmupdate.pl',
|
'zmupdate.pl',
|
||||||
|
'zmstats.pl',
|
||||||
'zmtrack.pl',
|
'zmtrack.pl',
|
||||||
'zmtelemetry.pl'
|
'zmtelemetry.pl'
|
||||||
);
|
);
|
||||||
|
@ -149,8 +148,11 @@ socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" );
|
||||||
|
|
||||||
my $saddr = sockaddr_un( SOCK_FILE );
|
my $saddr = sockaddr_un( SOCK_FILE );
|
||||||
my $server_up = connect( CLIENT, $saddr );
|
my $server_up = connect( CLIENT, $saddr );
|
||||||
|
|
||||||
if ( ! $server_up ) {
|
if ( ! $server_up ) {
|
||||||
if ( $Config{ZM_SERVER_ID} ) {
|
if ( $Config{ZM_SERVER_ID} ) {
|
||||||
|
use Sys::MemInfo qw(totalmem freemem totalswap freeswap);
|
||||||
|
use Sys::CpuLoad;
|
||||||
if ( ! defined $dbh->do(q{UPDATE Servers SET Status=?,TotalMem=?,FreeMem=?,TotalSwap=?,FreeSwap=? WHERE Id=?}, undef,
|
if ( ! defined $dbh->do(q{UPDATE Servers SET Status=?,TotalMem=?,FreeMem=?,TotalSwap=?,FreeSwap=? WHERE Id=?}, undef,
|
||||||
'NotRunning', &totalmem, &freemem, &totalswap, &freeswap, $Config{ZM_SERVER_ID} ) ) {
|
'NotRunning', &totalmem, &freemem, &totalswap, &freeswap, $Config{ZM_SERVER_ID} ) ) {
|
||||||
Error("Failed Updating status of Server record to Not RUnning for Id=$Config{ZM_SERVER_ID}" . $dbh->errstr());
|
Error("Failed Updating status of Server record to Not RUnning for Id=$Config{ZM_SERVER_ID}" . $dbh->errstr());
|
||||||
|
@ -282,6 +284,13 @@ sub run {
|
||||||
my $win = $rin;
|
my $win = $rin;
|
||||||
my $ein = $win;
|
my $ein = $win;
|
||||||
my $timeout = 1;
|
my $timeout = 1;
|
||||||
|
my $Server = undef;
|
||||||
|
|
||||||
|
if ( $Config{ZM_SERVER_ID} ) {
|
||||||
|
require ZoneMinder::Server;
|
||||||
|
$Server = new ZoneMinder::Server( $Config{ZM_SERVER_ID} );
|
||||||
|
}
|
||||||
|
|
||||||
while( 1 ) {
|
while( 1 ) {
|
||||||
if ( $Config{ZM_SERVER_ID} ) {
|
if ( $Config{ZM_SERVER_ID} ) {
|
||||||
$dbh = zmDbConnect() if ! $dbh->ping();
|
$dbh = zmDbConnect() if ! $dbh->ping();
|
||||||
|
@ -297,12 +306,16 @@ sub run {
|
||||||
my $paddr = accept( CLIENT, SERVER );
|
my $paddr = accept( CLIENT, SERVER );
|
||||||
my $message = <CLIENT>;
|
my $message = <CLIENT>;
|
||||||
|
|
||||||
next if ( !$message );
|
next if !$message;
|
||||||
|
|
||||||
my ( $command, $daemon, @args ) = split( /;/, $message );
|
my ( $command, $daemon, @args ) = split( /;/, $message );
|
||||||
|
|
||||||
if ( $command eq 'start' ) {
|
if ( $command eq 'start' ) {
|
||||||
|
if ( $Server and exists $$Server{$daemon} and ! $$Server{$daemon} ) {
|
||||||
|
Debug("Not running $daemon because it is turned off for this server.");
|
||||||
|
} else {
|
||||||
start( $daemon, @args );
|
start( $daemon, @args );
|
||||||
|
}
|
||||||
} elsif ( $command eq 'stop' ) {
|
} elsif ( $command eq 'stop' ) {
|
||||||
stop( $daemon, @args );
|
stop( $daemon, @args );
|
||||||
} elsif ( $command eq 'restart' ) {
|
} elsif ( $command eq 'restart' ) {
|
||||||
|
@ -578,7 +591,8 @@ sub reload {
|
||||||
sub logrot {
|
sub logrot {
|
||||||
logReinit();
|
logReinit();
|
||||||
foreach my $process ( values( %pid_hash ) ) {
|
foreach my $process ( values( %pid_hash ) ) {
|
||||||
if ( $process->{pid} && $process->{command} =~ /^zm.*\.pl/ ) {
|
if ( $process->{pid} ) {
|
||||||
|
# && $process->{command} =~ /^zm.*\.pl/ ) {
|
||||||
kill( 'HUP', $process->{pid} );
|
kill( 'HUP', $process->{pid} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue