diff --git a/bin/sau b/bin/sau index 77db1fc..f8286e8 100755 --- a/bin/sau +++ b/bin/sau @@ -45,8 +45,13 @@ def init(): log.addHandler(handler) -def fork_and_reboot(): +def fork_and_reboot(report_success=True): log = logging.getLogger(sau.LOGNAME) + if report_success: + exit_code=0 + else: + exit_code=1 + if os.path.exists('/proc/1/comm'): with open('/proc/1/comm', 'r') as f: if f.readline().strip() == 'systemd': @@ -56,7 +61,7 @@ def fork_and_reboot(): try: pid = os.fork() if pid != 0: - sys.exit(0) + sys.exit(exit_code) except OSError as err: log.error("Fork #1 failed when going for reboot: {}".format(err)) sys.exit(1) @@ -83,8 +88,6 @@ def fork_and_reboot(): os.dup2(stdout.fileno(), sys.stdout.fileno()) os.dup2(stderr.fileno(), sys.stderr.fileno()) - log.warning("New fork!") - # sleep for a short while to give parent time to exit time.sleep(30) try: @@ -121,7 +124,16 @@ def main(): elif reboot_recommended: log.info('Rebooting because service restarts did not close all deleted files') if reboot_required or reboot_recommended: - fork_and_reboot() + fork_and_reboot(report_success=conf.getboolean('default', 'reboot_is_success', Fallback=True)) + + if reboot_required: + log.warning("Upgrade was success, but a reboot is required due to a system upgrade") + return 1 + elif reboot_recommended: + log.warning("Some services still uses old, deleted, files. You probably want to reboot") + return 1 + + return 0 def _conf_level_to_logging_level(conf_level): diff --git a/config.cfg b/config.cfg index 0addab2..a815b71 100644 --- a/config.cfg +++ b/config.cfg @@ -16,6 +16,9 @@ version_sensitivity=1 # not close all deleted files (any platform) do_reboot=no +# Set to 0 to exit with failure code when going for reboot. +reboot_is_success=yes + # Attempt to do a system upgrade # FreeBSD: upgrade to latest patch version using freebsd-update fetch install # Gentoo: allow upgrade of sys-kernel/-packages, clean old kernels, and update grub-config