@ -28,6 +28,7 @@ my $anvil = Anvil::Tools->new();
$anvil->Get->switches({list => [
"enable",
"disable",
"log-only",
"monitor",
"now",
"start",
@ -66,14 +67,14 @@ foreach my $daemon (sort {$a cmp $b} keys %{$anvil->data->{daemons}{$host_type}}
push @{$daemon_list}, $daemon;
}
if ($anvil->data->{switches}{monitor})
if (( $anvil->data->{switches}{monitor}) or ($anvil->data->{switches}{'log-only'}) )
{
# Run as a daemon
monitor_daemons($anvil);
}
elsif ($anvil->data->{switches}{status})
{
report_status($anvil);
report_status($anvil, "stdout" );
}
else
{
@ -103,14 +104,20 @@ $anvil->nice_exit({exit_code => 0});
sub report_status
{
my ($anvil) = @_;
my ($anvil, $target ) = @_;
# Return Code meanings:
# - Enabled = 0, Disabled = 1
# - Started = 0, Stopped = 3
# - Failed = 0, OK = 1,
print "Anvil! Intelligent Availability Daemon Status (Enabled, Started, Failed);\n";
check_daemon($anvil);
my $print = $target eq "stdout" ? 1 : 0;
# Only print the header if we're printing to STDOUT
if ($print)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => $print, level => 1, secure => 0, key => "message_0419"});
}
my $longest_daemon = $anvil->data->{longest_daemon};
foreach my $daemon (sort {$a cmp $b} keys %{$anvil->data->{daemon}})
{
@ -154,7 +161,17 @@ sub report_status
{
$say_daemon .= ".";
}
print " - ".$say_daemon." ".$say_enabled." (".$anvil->data->{daemon}{$daemon}{enabled}{string}."), ".$say_started." (".$anvil->data->{daemon}{$daemon}{active}{string}."), ".$say_failed." (".$anvil->data->{daemon}{$daemon}{failed}{string}.")\n";
# Report.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => $print, level => 1, secure => 0, key => "message_0420", variables => {
daemon => $say_daemon,
enabled => $say_enabled,
enable_string => $anvil->data->{daemon}{$daemon}{enabled}{string},
started => $say_started,
start_string => $anvil->data->{daemon}{$daemon}{active}{string},
failed => $say_failed,
fail_string => $anvil->data->{daemon}{$daemon}{failed}{string},
}});
}
return(0);
@ -294,7 +311,7 @@ sub process_daemons
print "Done.\n\n";
sleep 1;
report_status($anvil);
report_status($anvil, "stdout" );
return(0);
}
@ -315,7 +332,8 @@ sub monitor_daemons
}
check_daemon($anvil);
if ($anvil->data->{switches}{monitor})
{
foreach my $daemon (sort {$a cmp $b} keys %{$anvil->data->{daemon}})
{
# Return code of '1' is OK, '0' is failed.
@ -341,6 +359,11 @@ sub monitor_daemons
}});
}
}
}
else
{
report_status($anvil, "log");
}
if (time > $next_md5sum_check)
{
@ -353,7 +376,7 @@ sub monitor_daemons
$anvil->nice_exit({exit_code => 0});
}
}
sleep 5 ;
sleep 10 ;
}
return(0);