Added log-only option to anvil-manage-daemons and enabled

anvil-monitor-daemons.service to only monitor daemons.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 10 months ago
parent 1455066cd1
commit e0c4ed6de5
  1. 1
      anvil.spec.in
  2. 3
      man/anvil-manage-daemons.8
  3. 2
      share/words.xml
  4. 79
      tools/anvil-manage-daemons
  5. 2
      units/anvil-monitor-daemons.service

@ -249,6 +249,7 @@ setenforce 0
### TODO: check it if was disabled (if it existed before) and, if so, leave it disabled.
systemctl enable --now chronyd.service
systemctl enable --now anvil-daemon.service
systemctl enable --now anvil-monitor-daemons.service
systemctl enable --now anvil-monitor-network.service
systemctl enable --now anvil-monitor-performance.service
systemctl enable --now scancore.service

@ -27,6 +27,9 @@ All Anvil! daemons that are not enabled will be enabled.
\fB\-\-disable\fR
All Anvil! daemons that are not disabled will be disabled.
.TP
\fB\-\-log\-only\fR
if this is passed, it monitors the status of the daemons, but does not try to recover failed ones.
.TP
\fB\-\-monitor\fR
This is set to the job UUID when the request to boot is coming from a database job. When set, the referenced job will be updated and marked as complete / failed when the run completes.
.TP

@ -3361,6 +3361,8 @@ proceeding.
<key name="message_0416">[ Note ] - The network has reconnected to the database, configuring will complete shortly.</key>
<key name="message_0417">[ Note ] - The old 'ifcfg' style config file: [#!variable!file!#] will be backed up and then removed!</key>
<key name="message_0418">[ Note ] - Updated the ssh daemon config file: [#!variable!file!#] to enable ssh access for the root user.</key>
<key name="message_0419">Anvil! Intelligent Availability Daemon Status (Enabled, Started, Failed);</key>
<key name="message_0420">- #!variable!daemon!# #!variable!enabled!# (#!variable!enable_string!#), #!variable!started!# (#!variable!start_string!#), #!variable!failed!# (#!variable!fail_string!#).</key>
<!-- Translate names (protocols, etc) -->
<key name="name_0001">Normal Password</key> <!-- none in mail-server -->

@ -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,32 +332,38 @@ sub monitor_daemons
}
check_daemon($anvil);
foreach my $daemon (sort {$a cmp $b} keys %{$anvil->data->{daemon}})
if ($anvil->data->{switches}{monitor})
{
# Return code of '1' is OK, '0' is failed.
my $string = $anvil->data->{daemon}{$daemon}{failed}{string};
my $return_code = $anvil->data->{daemon}{$daemon}{failed}{return_code};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:daemon" => $daemon,
"s2:string" => $string,
"s3:return_code" => $return_code,
}});
if (not $return_code)
foreach my $daemon (sort {$a cmp $b} keys %{$anvil->data->{daemon}})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "warning_0171", variables => { daemon => $daemon }});
my $shell_call = $anvil->data->{path}{exe}{systemctl}." restart ".$daemon;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({debug => 2, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => {
output => $output,
return_code => $return_code,
# Return code of '1' is OK, '0' is failed.
my $string = $anvil->data->{daemon}{$daemon}{failed}{string};
my $return_code = $anvil->data->{daemon}{$daemon}{failed}{return_code};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:daemon" => $daemon,
"s2:string" => $string,
"s3:return_code" => $return_code,
}});
if (not $return_code)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "warning_0171", variables => { daemon => $daemon }});
my $shell_call = $anvil->data->{path}{exe}{systemctl}." restart ".$daemon;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({debug => 2, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => {
output => $output,
return_code => $return_code,
}});
}
}
}
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);

@ -4,7 +4,7 @@ Wants=network.target
[Service]
Type=simple
ExecStart=/usr/sbin/anvil-manage-daemons --monitor
ExecStart=/usr/sbin/anvil-manage-daemons --log-only
ExecStop=/bin/kill -WINCH ${MAINPID}
Restart=always
RestartSec=60

Loading…
Cancel
Save