74 lines
2.1 KiB
Python
Executable File
74 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3.6
|
|
import configparser
|
|
import logging
|
|
import logging.handlers
|
|
import os
|
|
import platform
|
|
import sys
|
|
import time
|
|
|
|
import sau
|
|
import sau.services
|
|
import sau.platforms
|
|
|
|
|
|
def main():
|
|
conf = sau.config
|
|
log = logging.getLogger(sau.LOGNAME)
|
|
platform = sau.platforms.get_platform()
|
|
|
|
reboot_required = False
|
|
reboot_recommended = False
|
|
|
|
if conf.getboolean('default', 'do_system_upgrade', fallback=True):
|
|
reboot_required = platform.system_upgrade()
|
|
|
|
if conf.getboolean('default', 'do_package_upgrade', fallback=True):
|
|
platform.pkg_upgrade()
|
|
|
|
if conf.getboolean('default', 'do_service_restart', fallback=True):
|
|
reboot_recommended = sau.services.restart_services()
|
|
|
|
if conf.getboolean('default', 'do_reboot', fallback=False):
|
|
if reboot_required:
|
|
log.warning('Rebooting because of a system upgrade')
|
|
elif reboot_recommended:
|
|
log.warning('Rebooting because service restarts did not close all deleted files')
|
|
if reboot_required or reboot_recommended:
|
|
# sleep a little to make sure the above log-messages has reached
|
|
# syslog before we reboot
|
|
time.sleep(1)
|
|
os.system('/sbin/reboot')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sau.config = configparser.SafeConfigParser()
|
|
conf = sau.config
|
|
|
|
if platform.system() == 'FreeBSD':
|
|
syslog_socket = '/var/run/log'
|
|
conf_file = '/usr/local/etc/sau.cfg'
|
|
else:
|
|
syslog_socket = '/dev/log'
|
|
conf_file = '/etc/sau.cfg'
|
|
|
|
if os.path.isfile(conf_file):
|
|
conf.read(conf_file)
|
|
|
|
log = logging.getLogger(sau.LOGNAME)
|
|
log.setLevel(logging.DEBUG)
|
|
|
|
handler = logging.StreamHandler()
|
|
formatter = logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s')
|
|
handler.setFormatter(formatter)
|
|
handler.setLevel(logging.DEBUG)
|
|
log.addHandler(handler)
|
|
|
|
|
|
handler = logging.handlers.SysLogHandler(address=syslog_socket)
|
|
formatter = logging.Formatter(fmt='{}[%(process)s] %(message)s'.format(sau.LOGNAME))
|
|
handler.setFormatter(formatter)
|
|
handler.setLevel(logging.INFO)
|
|
log.addHandler(handler)
|
|
sys.exit(main())
|