From 7b715270f0720c565af50e102d761cd83cb3569b Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 22 Aug 2012 17:02:54 -0400 Subject: 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 --- cloudinit/config/cc_apt_update_upgrade.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'cloudinit/config') 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)) -- cgit v1.2.3