@ -28,6 +28,7 @@ my $anvil = Anvil::Tools->new();
$anvil->Get->switches({list => [
$anvil->Get->switches({list => [
"enable",
"enable",
"disable",
"disable",
"log-only",
"monitor",
"monitor",
"now",
"now",
"start",
"start",
@ -66,14 +67,14 @@ foreach my $daemon (sort {$a cmp $b} keys %{$anvil->data->{daemons}{$host_type}}
push @{$daemon_list}, $daemon;
push @{$daemon_list}, $daemon;
}
}
if ($anvil->data->{switches}{monitor})
if (( $anvil->data->{switches}{monitor}) or ($anvil->data->{switches}{'log-only'}) )
{
{
# Run as a daemon
# Run as a daemon
monitor_daemons($anvil);
monitor_daemons($anvil);
}
}
elsif ($anvil->data->{switches}{status})
elsif ($anvil->data->{switches}{status})
{
{
report_status($anvil);
report_status($anvil, "stdout" );
}
}
else
else
{
{
@ -103,14 +104,20 @@ $anvil->nice_exit({exit_code => 0});
sub report_status
sub report_status
{
{
my ($anvil) = @_;
my ($anvil, $target ) = @_;
# Return Code meanings:
# Return Code meanings:
# - Enabled = 0, Disabled = 1
# - Enabled = 0, Disabled = 1
# - Started = 0, Stopped = 3
# - Started = 0, Stopped = 3
# - Failed = 0, OK = 1,
# - Failed = 0, OK = 1,
print "Anvil! Intelligent Availability Daemon Status (Enabled, Started, Failed);\n";
check_daemon($anvil);
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};
my $longest_daemon = $anvil->data->{longest_daemon};
foreach my $daemon (sort {$a cmp $b} keys %{$anvil->data->{daemon}})
foreach my $daemon (sort {$a cmp $b} keys %{$anvil->data->{daemon}})
{
{
@ -154,7 +161,17 @@ sub report_status
{
{
$say_daemon .= ".";
$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);
return(0);
@ -294,7 +311,7 @@ sub process_daemons
print "Done.\n\n";
print "Done.\n\n";
sleep 1;
sleep 1;
report_status($anvil);
report_status($anvil, "stdout" );
return(0);
return(0);
}
}
@ -315,7 +332,8 @@ sub monitor_daemons
}
}
check_daemon($anvil);
check_daemon($anvil);
if ($anvil->data->{switches}{monitor})
{
foreach my $daemon (sort {$a cmp $b} keys %{$anvil->data->{daemon}})
foreach my $daemon (sort {$a cmp $b} keys %{$anvil->data->{daemon}})
{
{
# Return code of '1' is OK, '0' is failed.
# 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)
if (time > $next_md5sum_check)
{
{
@ -353,7 +376,7 @@ sub monitor_daemons
$anvil->nice_exit({exit_code => 0});
$anvil->nice_exit({exit_code => 0});
}
}
}
}
sleep 5 ;
sleep 10 ;
}
}
return(0);
return(0);