summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStig Thormodsrud <stig@vyatta.com>2010-03-16 20:19:35 -0700
committerStig Thormodsrud <stig@vyatta.com>2010-03-16 20:19:35 -0700
commit9dd9f5cfce52f22c88112da863a4a5bf7d5f3668 (patch)
tree131a25e3d0055e404a56c1655ce636fbeefd2f52
parent45d1688244b6d9f539c2f5a258a42d6d710bc595 (diff)
downloadvyatta-op-9dd9f5cfce52f22c88112da863a4a5bf7d5f3668.tar.gz
vyatta-op-9dd9f5cfce52f22c88112da863a4a5bf7d5f3668.zip
Add "reboot now" to prevent confirmation prompt.
-rwxr-xr-xscripts/vyatta-reboot.pl47
-rw-r--r--templates/reboot/now/node.def2
2 files changed, 36 insertions, 13 deletions
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;
}
diff --git a/templates/reboot/now/node.def b/templates/reboot/now/node.def
new file mode 100644
index 0000000..2171b45
--- /dev/null
+++ b/templates/reboot/now/node.def
@@ -0,0 +1,2 @@
+help: Reboot the system without confirmation
+run: sudo /opt/vyatta/bin/sudo-users/vyatta-reboot.pl --action reboot --now