From 9dd9f5cfce52f22c88112da863a4a5bf7d5f3668 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Tue, 16 Mar 2010 20:19:35 -0700 Subject: Add "reboot now" to prevent confirmation prompt. --- scripts/vyatta-reboot.pl | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'scripts/vyatta-reboot.pl') diff --git a/scripts/vyatta-reboot.pl b/scripts/vyatta-reboot.pl index 2106ade..4d34fee 100755 --- a/scripts/vyatta-reboot.pl +++ b/scripts/vyatta-reboot.pl @@ -63,13 +63,30 @@ sub is_reboot_pending { } } +sub do_reboot { + my $login = shift; + + syslog("warning", "Reboot now requested by $login"); + exec("sudo /sbin/reboot"); +} + +sub cancel_reboot { + my ($login, $time) = @_; + + my $job = `cat $reboot_job_file`; + chomp $job; + system("atrm $job"); + system("rm $reboot_job_file"); + syslog("warning", "Reboot scheduled for [$time] - CANCELED by $login"); +} # # main # -my ($action, $at_time); +my ($action, $at_time, $now); GetOptions("action=s" => \$action, "at_time=s" => \$at_time, + "now!" => \$now, ); if (! defined $action) { @@ -86,16 +103,24 @@ if ($action eq "reboot") { my ($rc, $time) = is_reboot_pending(); if ($rc) { - print "Reboot already scheduled for [$time]\n"; - exit 1; + if (defined $now) { + cancel_reboot($login, $time); + do_reboot($login); + } else { + print "Reboot already scheduled for [$time]\n"; + exit 1; + } } - if (prompt("Proceed with reboot? [confirm]", -y1d=>"y")) { - syslog("warning", "Reboot now requested by $login"); - exec("sudo /sbin/reboot"); + if (defined $now) { + do_reboot($login); } else { - print "Reboot canceled\n"; - exit 1; + if (prompt("Proceed with reboot? [confirm]", -y1d=>"y")) { + do_reboot($login); + } else { + print "Reboot canceled\n"; + exit 1; + } } } @@ -158,12 +183,8 @@ if ($action eq "reboot_cancel") { print "No reboot currently scheduled\n"; exit 1; } - my $job = `cat $reboot_job_file`; - chomp $job; - system("atrm $job"); - system("rm $reboot_job_file"); + cancel_reboot($login, $time); print "Reboot canceled\n"; - syslog("warning", "Reboot scheduled for [$time] - CANCELED by $login"); exit 0; } -- cgit v1.2.3