X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=clearadm%2Fcleartasks.pl;fp=clearadm%2Fcleartasks.pl;h=25a297beeed3c0272859207885e112a2af163762;hb=0c802537ec02d6cfea4c41b3138535c09a319489;hp=66c964b1723d90858ca6b022610048094c228587;hpb=bdb1e0c845a6921e22d52fbff3404d5c1dfae520;p=clearscm.git diff --git a/clearadm/cleartasks.pl b/clearadm/cleartasks.pl index 66c964b..25a297b 100755 --- a/clearadm/cleartasks.pl +++ b/clearadm/cleartasks.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl =pod @@ -47,6 +47,9 @@ $Date: 2013/06/02 18:47:26 $ Examine the Clearadm schedule and perform the tasks required. +Note that sending the Cleartasks.pl process a sigusr1 will cause it to toggle +verbose mode. + =cut use strict; @@ -54,6 +57,7 @@ use warnings; use FindBin; use Getopt::Long; +use Sys::Hostname; use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib"; @@ -67,7 +71,10 @@ use Utils; my $VERSION = '$Revision: 1.25 $'; ($VERSION) = ($VERSION =~ /\$Revision: (.*) /); -my $logfile = "$Clearadm::CLEAROPTS{CLEARADM_LOGDIR}/$FindBin::Script.log"; +my $logfile = "$Clearadm::CLEAROPTS{CLEARADM_LOGDIR}/$FindBin::Script"; + $logfile =~ s/\.pl$//; + $logfile .= '.' . hostname() . '.log'; + my $pidfile = "$Clearadm::CLEAROPTS{CLEARADM_RUNDIR}/$FindBin::Script.pid"; my $daemon = 1; @@ -76,6 +83,18 @@ $ENV{PATH} .= ":$Clearadm::CLEAROPTS{CLEARADM_BASE}"; my ($clearadm, $clearexec); +sub ToggleVerbose() { + if (get_verbose) { + display 'Turning verbose off'; + set_verbose 0; + } else { + display 'Turning verbose on'; + set_verbose 1; + } # if +} # ToggleVerbose + +$SIG{USR1} = \&ToggleVerbose; + sub HandleSystemNotCheckingIn (%) { my (%system) = @_; @@ -131,7 +150,7 @@ END } # HandleSystemNotCheckingIn sub SystemsCheckin () { - foreach ($clearadm->FindSystem) { + for ($clearadm->FindSystem) { my %system = %$_; next if $system{active} eq 'false'; @@ -163,7 +182,7 @@ sub SystemsCheckin () { $clearadm->ClearNotifications ($system{name}) if $system{notification} and $system{notification} eq 'Heartbeat'; - } # foreach + } # for return; } # SystemsCheckin @@ -225,7 +244,7 @@ sub ProcessLoadavgErrors ($$$$@) { my $when = Today2SQLDatetime; - foreach (@output) { + for (@output) { # We need to log this output. Write it to STDOUT display $_; @@ -285,7 +304,7 @@ END undef, $lastid, ); - } # foreach + } # for return; } # ProcessLoadAvgErrors @@ -300,7 +319,7 @@ sub ProcessFilesystemErrors ($$$$@) { my %system; - foreach (@output) { + for (@output) { # We need to log this output. Write it to STDOUT display $_; @@ -317,9 +336,9 @@ sub ProcessFilesystemErrors ($$$$@) { $system{$1} = \%fsinfo; } # if } # if - } # foreach + } # for - foreach my $systemName (keys %system) { + for my $systemName (keys %system) { my @fsinfo; if (ref $system{$systemName} eq 'HASH') { @@ -340,7 +359,7 @@ were over their threshold.

"; @@ -362,7 +381,7 @@ END undef, $lastid, ); - } # foreach + } # for return; } # ProcessFilesystemErrors @@ -518,26 +537,28 @@ while () { my ($sleep, @workItems) = $clearadm->GetWork; - foreach (@workItems) { + for (@workItems) { my %scheduledTask = %{$_}; $scheduledTask{system} ||= 'All systems'; if ($scheduledTask{system} =~ /all systems/i) { - foreach my $system ($clearadm->FindSystem) { + for my $system ($clearadm->FindSystem) { + next if $$system{active} eq 'false'; + $scheduledTask{system} = $$system{name}; $sleep = ExecuteTask $sleep, %scheduledTask; - } # foreach + } # for } else { $sleep = ExecuteTask $sleep, %scheduledTask; } # if - } # foreach + } # for if ($sleep > 0) { verbose "Sleeping for $sleep seconds"; sleep $sleep; } # if -} # foreach +} # for =pod