* Renamed tools/anvil-clear-reboot to tools/anvil-reboot-needed and changed it to behave like anvil-maintenance-mode. Signed-off-by: Digimer <digimer@alteeve.ca>main
parent
0191f93bad
commit
18455ab5f7
9 changed files with 224 additions and 76 deletions
@ -1,55 +0,0 @@ |
|||||||
#!/usr/bin/perl |
|
||||||
# |
|
||||||
# Exit codes; |
|
||||||
# 0 = Normal exit. |
|
||||||
# 1 = No database connections available. |
|
||||||
|
|
||||||
use strict; |
|
||||||
use warnings; |
|
||||||
use Anvil::Tools; |
|
||||||
|
|
||||||
# Disable buffering |
|
||||||
$| = 1; |
|
||||||
|
|
||||||
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; |
|
||||||
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; |
|
||||||
if (($running_directory =~ /^\./) && ($ENV{PWD})) |
|
||||||
{ |
|
||||||
$running_directory =~ s/^\./$ENV{PWD}/; |
|
||||||
} |
|
||||||
|
|
||||||
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1}); |
|
||||||
|
|
||||||
$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"}); |
|
||||||
|
|
||||||
# Read switches |
|
||||||
$anvil->Get->switches; |
|
||||||
|
|
||||||
# Connect to DBs. |
|
||||||
$anvil->Database->connect; |
|
||||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); |
|
||||||
if (not $anvil->data->{sys}{database}{connections}) |
|
||||||
{ |
|
||||||
# No databases, exit. |
|
||||||
print $anvil->Words->string({key => "error_0003"})."\n"; |
|
||||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, key => "error_0003"}); |
|
||||||
$anvil->nice_exit({exit_code => 1}); |
|
||||||
} |
|
||||||
|
|
||||||
# If the uptime is less than ten minutes, clear the reboot flag. |
|
||||||
my $uptime = $anvil->Storage->read_file({file => $anvil->data->{path}{proc}{uptime}}); |
|
||||||
|
|
||||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0200"}); |
|
||||||
$anvil->Database->insert_or_update_variables({ |
|
||||||
variable_name => "reboot::needed", |
|
||||||
variable_value => "0", |
|
||||||
variable_default => "0", |
|
||||||
variable_description => "striker_0089", |
|
||||||
variable_section => "system", |
|
||||||
variable_source_uuid => $anvil->Get->host_uuid, |
|
||||||
variable_source_table => "hosts", |
|
||||||
update_value_only => 1, |
|
||||||
}); |
|
||||||
|
|
||||||
# We're done |
|
||||||
$anvil->nice_exit({exit_code => 0}); |
|
@ -0,0 +1,101 @@ |
|||||||
|
#!/usr/bin/perl |
||||||
|
# |
||||||
|
# This set, clear and report if the host needs to be rebooted. |
||||||
|
# |
||||||
|
# Examples; |
||||||
|
# - Enable - anvil-reboot-needed --set 1 |
||||||
|
# - Disable - anvil-reboot-needed --set 0 |
||||||
|
# - Report - anvil-reboot-needed |
||||||
|
# |
||||||
|
# Exit codes; |
||||||
|
# 0 = Normal exit. |
||||||
|
# 1 = No database connections available. |
||||||
|
|
||||||
|
use strict; |
||||||
|
use warnings; |
||||||
|
use Anvil::Tools; |
||||||
|
|
||||||
|
# Disable buffering |
||||||
|
$| = 1; |
||||||
|
|
||||||
|
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; |
||||||
|
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; |
||||||
|
if (($running_directory =~ /^\./) && ($ENV{PWD})) |
||||||
|
{ |
||||||
|
$running_directory =~ s/^\./$ENV{PWD}/; |
||||||
|
} |
||||||
|
|
||||||
|
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1}); |
||||||
|
|
||||||
|
$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"}); |
||||||
|
|
||||||
|
# Read switches |
||||||
|
$anvil->data->{switches}{set} = ""; |
||||||
|
$anvil->Get->switches; |
||||||
|
|
||||||
|
# Connect to DBs. |
||||||
|
$anvil->Database->connect; |
||||||
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"}); |
||||||
|
if (not $anvil->data->{sys}{database}{connections}) |
||||||
|
{ |
||||||
|
# No databases, exit. |
||||||
|
print $anvil->Words->string({key => "error_0003"})."\n"; |
||||||
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, key => "error_0003"}); |
||||||
|
$anvil->nice_exit({exit_code => 1}); |
||||||
|
} |
||||||
|
|
||||||
|
my $reboot_needed = $anvil->System->reboot_needed({debug => 2}); |
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { reboot_needed => $reboot_needed }}); |
||||||
|
|
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::set" => $anvil->data->{switches}{set} }}); |
||||||
|
if ($anvil->data->{switches}{set} eq "1") |
||||||
|
{ |
||||||
|
# Enable |
||||||
|
if (not $reboot_needed) |
||||||
|
{ |
||||||
|
$reboot_needed = $anvil->System->reboot_needed({debug => 2, set => 1}); |
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { reboot_needed => $reboot_needed }}); |
||||||
|
print $anvil->Words->string({key => "message_0048"})."\n"; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
# Was already set, do nothing |
||||||
|
print $anvil->Words->string({key => "message_0049"})."\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
elsif ($anvil->data->{switches}{set} eq "0") |
||||||
|
{ |
||||||
|
# Disabled |
||||||
|
if ($reboot_needed) |
||||||
|
{ |
||||||
|
$reboot_needed = $anvil->System->reboot_needed({debug => 2, set => 0}); |
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { reboot_needed => $reboot_needed }}); |
||||||
|
print $anvil->Words->string({key => "message_0050"})."\n"; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
# Was already disabled, do nothing |
||||||
|
print $anvil->Words->string({key => "message_0051"})."\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
elsif ($anvil->data->{switches}{set}) |
||||||
|
{ |
||||||
|
# Bad call |
||||||
|
print $anvil->Words->string({key => "message_0052", variables => { program => $THIS_FILE }})."\n"; |
||||||
|
} |
||||||
|
|
||||||
|
# Get the current state |
||||||
|
|
||||||
|
if ($reboot_needed) |
||||||
|
{ |
||||||
|
# Report that we're in mainteance mode |
||||||
|
print $anvil->Words->string({key => "message_0053"})."\n"; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
# Report that we're not. |
||||||
|
print $anvil->Words->string({key => "message_0054"})."\n"; |
||||||
|
} |
||||||
|
|
||||||
|
# We're done |
||||||
|
$anvil->nice_exit({exit_code => 0}); |
Loading…
Reference in new issue