summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-08-22 17:02:54 -0400
committerScott Moser <smoser@ubuntu.com>2012-08-22 17:02:54 -0400
commit7b715270f0720c565af50e102d761cd83cb3569b (patch)
tree0c871d9de02d2dc6f6c150807b6d9c76278b0501
parent43c55aca8c7ee17471b709a6a348c318db165a92 (diff)
downloadvyos-cloud-init-7b715270f0720c565af50e102d761cd83cb3569b.tar.gz
vyos-cloud-init-7b715270f0720c565af50e102d761cd83cb3569b.zip
add apt_reboot_if_required to reboot if required
If an upgrade or package installation forced a reboot (such as a kernel upgrade), then we can optionally reboot at that point. This allows the user to not be into the newest available kernel without needing a reboot on their own. LP: #1038108
-rw-r--r--ChangeLog2
-rw-r--r--cloudinit/config/cc_apt_update_upgrade.py15
2 files changed, 17 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index e9e88318..91f3834a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,6 @@
0.7.0:
+ - add apt_reboot_if_required to reboot if an upgrade or package installation
+ forced the need for one (LP: #1038108)
- allow distro mirror selection to include availability-zone (LP: #1037727)
- allow arch specific mirror selection (select ports.ubuntu.com on arm)
LP: #1028501
diff --git a/cloudinit/config/cc_apt_update_upgrade.py b/cloudinit/config/cc_apt_update_upgrade.py
index 49a93415..356bb98d 100644
--- a/cloudinit/config/cc_apt_update_upgrade.py
+++ b/cloudinit/config/cc_apt_update_upgrade.py
@@ -20,6 +20,7 @@
import glob
import os
+import time
from cloudinit import templater
from cloudinit import util
@@ -125,6 +126,20 @@ def handle(name, cfg, cloud, log, _args):
util.logexc(log, "Failed to install packages: %s ", pkglist)
errors.append(e)
+ # kernel and openssl (possibly some other packages)
+ # write a file /var/run/reboot-required after upgrading.
+ # if that file exists and configured, then just stop right now and reboot
+ # TODO(smoser): handle this less voilently
+ reboot_file = "/var/run/reboot-required"
+ if ((upgrade or pkglist) and cfg.get("apt_reboot_if_required", False) and
+ os.path.isfile(reboot_file)):
+ log.warn("rebooting after upgrade or install per %s" % reboot_file)
+ time.sleep(1) # give the warning time to get out
+ util.subp(["/sbin/reboot"])
+ time.sleep(60)
+ log.warn("requested reboot did not happen!")
+ errors.append(Exception("requested reboot did not happen!"))
+
if len(errors):
log.warn("%s failed with exceptions, re-raising the last one",
len(errors))