* Created System->reboot_needed() to set/clear/report if a reboot is needed.

* 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
Digimer 6 years ago
parent 0191f93bad
commit 18455ab5f7
  1. 82
      Anvil/Tools/System.pm
  2. 1
      cgi-bin/striker
  3. 7
      html/skins/alteeve/images/sources.txt
  4. 13
      html/skins/alteeve/striker.html
  5. 15
      share/words.xml
  6. 55
      tools/anvil-clear-reboot
  7. 2
      tools/anvil-maintenance-mode
  8. 101
      tools/anvil-reboot-needed
  9. 24
      tools/anvil-update-system

@ -29,6 +29,7 @@ my $THIS_FILE = "System.pm";
# ping # ping
# read_ssh_config # read_ssh_config
# reload_daemon # reload_daemon
# reboot_needed
# start_daemon # start_daemon
# stop_daemon # stop_daemon
# stty_echo # stty_echo
@ -1694,6 +1695,87 @@ sub reload_daemon
return($return); return($return);
} }
=head2 reboot_needed
This sets, clears or checks if the local system needs to be restart.
This returns C<< 1 >> if a reset is currently needed and C<< 0 >> if not.
Parameters;
=head3 set (optional)
If this is set to C<< 1 >>, the reset needed variable is set. If this is set to C<< 0 >>, reset needed is cleared.
=cut
sub reboot_needed
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $set = defined $parameter->{set} ? $parameter->{set} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { set => $set }});
if (($set) or ($set eq "0"))
{
### TODO: stop other systems from using this database.
# Am I enabling or disabling?
if ($set eq "1")
{
# Set
$anvil->Database->insert_or_update_variables({
debug => 2,
variable_name => "reboot::needed",
variable_value => "1",
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,
});
}
elsif ($set eq "0")
{
# Clear
$anvil->Database->insert_or_update_variables({
debug => 2,
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,
});
}
else
{
# Called with an invalid value.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "log_0197", variables => { set => $set }});
$set = "";
}
}
my ($reboot_needed, $variable_uuid, $modified_date) = $anvil->Database->read_variable({debug => $debug, variable_name => "reboot::needed"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
reboot_needed => $reboot_needed,
variable_uuid => $variable_uuid,
modified_date => $modified_date,
}});
if ($reboot_needed eq "")
{
$reboot_needed = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { reboot_needed => $reboot_needed }});
}
return($reboot_needed);
}
=head2 start_daemon =head2 start_daemon
This method starts a daemon. The return code from the start request will be returned. This method starts a daemon. The return code from the start request will be returned.

@ -238,6 +238,7 @@ sub process_task
{ {
# The 'back' goes home # The 'back' goes home
$anvil->data->{form}{back_link} = "?"; $anvil->data->{form}{back_link} = "?";
my $reset_icon =
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "striker-setup"}); $anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "striker-setup"});
} }
} }

@ -37,3 +37,10 @@ customize by Trusted Icons from the Noun Project (https://thenounproject.com/ter
configure by iconesia from the Noun Project (https://thenounproject.com/term/configure/1651241/) configure by iconesia from the Noun Project (https://thenounproject.com/term/configure/1651241/)
- build_icon.png - build_icon.png
power by Blair Adams from the Noun Project (https://thenounproject.com/search/?q=power&i=865890)
- power_icon.png
reset by Mooms from the Noun Project (https://thenounproject.com/search/?q=reset&i=1033425)
- reboot_icon.png

@ -257,6 +257,19 @@
#!string!striker_0059!# #!string!striker_0059!#
</td> </td>
</tr> </tr>
<tr>
<td rowspan="2" class="icon_button">
<a href="?striker=true&task=reset"><img src="#!data!skin::url!#/images/#!variable!reset_icon!#" class="top_icon" ></a>
</td>
<td class="menu_title">
<a href="?striker=true&task=reset">#!string!striker_0091!#</a>
</td>
</tr>
<tr>
<td class="menu_details">
#!variable!reset_message!#
</td>
</tr>
</table> </table>
<!-- end striker-setup --> <!-- end striker-setup -->

@ -78,6 +78,18 @@ Report maintenance mode: #!variable!program!#
<key name="message_0046">This system is in maintenance mode.</key> <key name="message_0046">This system is in maintenance mode.</key>
<key name="message_0047">This system is NOT in maintenance mode.</key> <key name="message_0047">This system is NOT in maintenance mode.</key>
<key name="message_0048">This system has been set to need a reboot.</key>
<key name="message_0049">This system was already set to need a reboot, nothing changed.</key>
<key name="message_0050">This system has has been set to no longer need a reboot.</key>
<key name="message_0051">This system was not in maintenance mode, nothing changed.</key>
<key name="message_0052">Bad call. Usage:
Set that a reboot is required: #!variable!program!# --set 1
Clear the need for a reboot: #!variable!program!# --set 0
Report if a reboot is needed: #!variable!program!#
</key>
<key name="message_0053">This system needs to be rebooted.</key>
<key name="message_0054">This system does NOT need to be rebooted.</key>
<!-- Log entries --> <!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key> <key name="log_0001">Starting: [#!variable!program!#].</key>
<key name="log_0002"> <key name="log_0002">
@ -441,6 +453,9 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="striker_0088">The system will be updated momentarily. This system will now be in maintenance mode until the update is complete.</key> <key name="striker_0088">The system will be updated momentarily. This system will now be in maintenance mode until the update is complete.</key>
<key name="striker_0089">This indicates whether this system needs to be rebooted or not.</key> <key name="striker_0089">This indicates whether this system needs to be rebooted or not.</key>
<key name="striker_0090">This system is in maintenance mode and is not currently available.</key> <key name="striker_0090">This system is in maintenance mode and is not currently available.</key>
<key name="striker_0091">Reset this Striker</key>
<key name="striker_0092">This option will restart the host operating system. This is not currently needed.</key>
<key name="striker_0093">This machine needs to be rebooted. This option will restart the host operating system.</key>
<!-- Strings used by jobs --> <!-- Strings used by jobs -->
<key name="job_0001">Configure Network</key> <key name="job_0001">Configure Network</key>

@ -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});

@ -1,6 +1,6 @@
#!/usr/bin/perl #!/usr/bin/perl
# #
# This set, clears or reports if the host is in mainentance mode or not. # This set, clear and report if the host is in mainentance mode or not.
# #
# Examples; # Examples;
# - Enable - anvil-maintenance-mode --set 1 # - Enable - anvil-maintenance-mode --set 1

@ -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});

@ -114,16 +114,8 @@ my ($reboot) = run_os_update($anvil);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { reboot => $reboot }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { reboot => $reboot }});
# We're done updating # We're done updating
my ($reboot_needed, $variable_uuid, $modified_date) = $anvil->Database->read_variable({ my $reboot_needed = $anvil->System->reboot_needed({debug => 2, set => 1});
variable_name => "reboot::needed", $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { reboot_needed => $reboot_needed }});
variable_source_uuid => $anvil->Get->host_uuid,
variable_source_table => "hosts",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
reboot_needed => $reboot_needed,
variable_uuid => $variable_uuid,
modified_date => $modified_date,
}});
if ($reboot_needed) if ($reboot_needed)
{ {
update_progress($anvil, 100, "message_0039"); update_progress($anvil, 100, "message_0039");
@ -220,17 +212,9 @@ sub run_os_update
{ {
# Reboot will be needed. # Reboot will be needed.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0199"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0199"});
$anvil->Database->insert_or_update_variables({
variable_name => "reboot::needed",
variable_value => "1",
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,
});
my $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 }});
} }
if ((not $verifying) && ($line =~ /^Verifying /i)) if ((not $verifying) && ($line =~ /^Verifying /i))

Loading…
Cancel
Save