proper return codes and warnings if reboot is required
This commit is contained in:
parent
76639d8472
commit
8bbd8dbec2
22
bin/sau
22
bin/sau
@ -45,8 +45,13 @@ def init():
|
|||||||
log.addHandler(handler)
|
log.addHandler(handler)
|
||||||
|
|
||||||
|
|
||||||
def fork_and_reboot():
|
def fork_and_reboot(report_success=True):
|
||||||
log = logging.getLogger(sau.LOGNAME)
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
|
if report_success:
|
||||||
|
exit_code=0
|
||||||
|
else:
|
||||||
|
exit_code=1
|
||||||
|
|
||||||
if os.path.exists('/proc/1/comm'):
|
if os.path.exists('/proc/1/comm'):
|
||||||
with open('/proc/1/comm', 'r') as f:
|
with open('/proc/1/comm', 'r') as f:
|
||||||
if f.readline().strip() == 'systemd':
|
if f.readline().strip() == 'systemd':
|
||||||
@ -56,7 +61,7 @@ def fork_and_reboot():
|
|||||||
try:
|
try:
|
||||||
pid = os.fork()
|
pid = os.fork()
|
||||||
if pid != 0:
|
if pid != 0:
|
||||||
sys.exit(0)
|
sys.exit(exit_code)
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
log.error("Fork #1 failed when going for reboot: {}".format(err))
|
log.error("Fork #1 failed when going for reboot: {}".format(err))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -83,8 +88,6 @@ def fork_and_reboot():
|
|||||||
os.dup2(stdout.fileno(), sys.stdout.fileno())
|
os.dup2(stdout.fileno(), sys.stdout.fileno())
|
||||||
os.dup2(stderr.fileno(), sys.stderr.fileno())
|
os.dup2(stderr.fileno(), sys.stderr.fileno())
|
||||||
|
|
||||||
log.warning("New fork!")
|
|
||||||
|
|
||||||
# sleep for a short while to give parent time to exit
|
# sleep for a short while to give parent time to exit
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
try:
|
try:
|
||||||
@ -121,7 +124,16 @@ def main():
|
|||||||
elif reboot_recommended:
|
elif reboot_recommended:
|
||||||
log.info('Rebooting because service restarts did not close all deleted files')
|
log.info('Rebooting because service restarts did not close all deleted files')
|
||||||
if reboot_required or reboot_recommended:
|
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):
|
def _conf_level_to_logging_level(conf_level):
|
||||||
|
@ -16,6 +16,9 @@ version_sensitivity=1
|
|||||||
# not close all deleted files (any platform)
|
# not close all deleted files (any platform)
|
||||||
do_reboot=no
|
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
|
# Attempt to do a system upgrade
|
||||||
# FreeBSD: upgrade to latest patch version using freebsd-update fetch install
|
# 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
|
# Gentoo: allow upgrade of sys-kernel/-packages, clean old kernels, and update grub-config
|
||||||
|
Loading…
Reference in New Issue
Block a user