update upgrade all function
This commit is contained in:
parent
594d05bfe8
commit
bda64a80f5
|
@ -619,7 +619,7 @@ class UnattendedUpgradesShutdown():
|
|||
pass
|
||||
'''
|
||||
return True
|
||||
|
||||
'''
|
||||
def run_polling(self, signal_handler):
|
||||
logging.warning(
|
||||
_("Unable to monitor PrepareForShutdown() signal, polling "
|
||||
|
@ -643,7 +643,7 @@ class UnattendedUpgradesShutdown():
|
|||
while not self.iter():
|
||||
# TODO iter on sigterm and sighup, too
|
||||
time.sleep(self.wait_period)
|
||||
|
||||
'''
|
||||
# 定时下载 执行函数
|
||||
def timing_download(self):
|
||||
env = copy.copy(os.environ)
|
||||
|
@ -704,6 +704,7 @@ class UnattendedUpgradesShutdown():
|
|||
# return 0
|
||||
|
||||
# set signal handlers
|
||||
'''
|
||||
def signal_handler(signum, frame):
|
||||
|
||||
logging.warning(
|
||||
|
@ -711,7 +712,7 @@ class UnattendedUpgradesShutdown():
|
|||
"only if it is running")
|
||||
self.stop_signal_received.set()
|
||||
#self.start_iterations()
|
||||
|
||||
|
||||
# fall back to polling without GLib
|
||||
try:
|
||||
hasattr(GLib, "MainLoop")
|
||||
|
@ -719,7 +720,7 @@ class UnattendedUpgradesShutdown():
|
|||
logging.error("MainLoop Not Found")
|
||||
#self.run_polling(signal_handler)
|
||||
return
|
||||
'''
|
||||
|
||||
for sig in (signal.SIGTERM, signal.SIGHUP):
|
||||
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, sig,
|
||||
signal_handler, None, None)
|
||||
|
@ -727,6 +728,45 @@ class UnattendedUpgradesShutdown():
|
|||
if self.options.wait_for_signal:
|
||||
def change_upgrade_policy_handler():
|
||||
if os.path.exist(UNATTENDED_UPGRADE_POLICY_FILE_PATH):
|
||||
autoupgradepolicy.reload_config()
|
||||
|
||||
random_time = get_random_time(autoupgradepolicy.GetOptionValue('downloadTime'),DOWNLOAD_RANDOM)
|
||||
background_scheduler.add_job(task,'cron', args=['download'],id='download', \
|
||||
hour = random_time.hour,minute = random_time.minute,replace_existing=True)
|
||||
|
||||
random_time = random_time + datetime.timedelta(minutes=INTERVAL_DOWN_INSTALL)
|
||||
background_scheduler.add_job(task,'cron', args=['install'],id='install', \
|
||||
hour = random_time.hour,minute = random_time.minute,replace_existing=True)
|
||||
|
||||
random_time = get_random_time(autoupgradepolicy.GetOptionValue('downloadTime'))
|
||||
background_scheduler.add_job(task,'cron', args=['predownload'],id='predownload', \
|
||||
hour = random_time.hour,minute = random_time.minute,replace_existing=True)
|
||||
|
||||
if autoupgradepolicy.GetOptionValue('autoUpgradeState') == 'on':
|
||||
random_time = get_random_time(autoupgradepolicy.GetOptionValue('downloadTime'),DOWNLOAD_RANDOM)
|
||||
if autoupgradepolicy.GetOptionValue('downloadMode') == 'timing':
|
||||
background_scheduler.add_job(task,'cron', args=['download'],id='download', \
|
||||
hour = random_time.hour,minute = random_time.minute,replace_existing=True)
|
||||
if autoupgradepolicy.GetOptionValue('installMode') == 'timing':
|
||||
random_time = random_time + datetime.timedelta(minutes=INTERVAL_DOWN_INSTALL)
|
||||
background_scheduler.add_job(task,'cron', args=['install'],id='install', \
|
||||
hour = random_time.hour,minute = random_time.minute,replace_existing=True)
|
||||
else:
|
||||
background_scheduler.pause_job('download')
|
||||
background_scheduler.pause_job('install')
|
||||
|
||||
if autoupgradepolicy.GetOptionValue('preDownload') == 'on':
|
||||
random_time = get_random_time(autoupgradepolicy.GetOptionValue('downloadTime'),DOWNLOAD_RANDOM)
|
||||
background_scheduler.add_job(task,'cron', args=['predownload'],id='download', \
|
||||
hour = random_time.hour,minute = random_time.minute,replace_existing=True)
|
||||
else:
|
||||
background_scheduler.pause_job('predownload')
|
||||
|
||||
joblist = background_scheduler.get_jobs()
|
||||
|
||||
for job in joblist:
|
||||
logging.debug("job:%s,next run time:%s"%(job.id,job.next_run_time))
|
||||
'''
|
||||
self.download_mode = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_DOWNLOAD_MODE)
|
||||
self.install_mode = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_INSTALL_MODE)
|
||||
self.preDownload = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_PREDOWNLOAD)
|
||||
|
@ -756,7 +796,7 @@ class UnattendedUpgradesShutdown():
|
|||
self.install_time['h'] = self.download_time_r['h']
|
||||
self.install_time['m'] = self.download_time_r['m'] + INTERVAL_DOWN_INSTALL
|
||||
self.install_time_r = convert_time_by_random(self.install_time, INSTALL_RANDOM)
|
||||
'''
|
||||
|
||||
logging.info("download random:%d,upgrade interval:%d"%(self.download_random,self.upgrade_interval))
|
||||
|
||||
if self.preDownload == FeatureSwitch.ON.value: #open download timing
|
||||
|
@ -794,7 +834,7 @@ class UnattendedUpgradesShutdown():
|
|||
self.download_job.pause()
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
'''
|
||||
|
||||
|
||||
if self.autoUpgrade == FeatureSwitch.OFF.value:
|
||||
logging.info("auto upgrade turned off,removing download and instal jobs...")
|
||||
|
@ -854,7 +894,7 @@ class UnattendedUpgradesShutdown():
|
|||
pass
|
||||
# logging.error(e)
|
||||
|
||||
'''
|
||||
|
||||
logging.info("upgrade time: [%d:%d] [%d:%d] predown[%s] autoupgrade[%s] d-mode[%s] i-mode[%s]",
|
||||
self.download_time_r['h'], self.download_time_r['m'],self.install_time_r['h'],self.install_time_r['m'],
|
||||
self.preDownload, self.autoUpgrade, self.download_mode, self.install_mode)
|
||||
|
@ -863,7 +903,17 @@ class UnattendedUpgradesShutdown():
|
|||
logging.debug("unattended-upgrades-policy.conf not exist")
|
||||
|
||||
def upgrade_all_now_handler():
|
||||
now=datetime.datetime.now()
|
||||
random_time = now + datetime.timedelta(minutes=DOWNLOAD_RANDOM)
|
||||
background_scheduler.add_job(task,'date', args=['download_and_install'],id='download', \
|
||||
hour = random_time.hour,minute = random_time.minute,replace_existing=True)
|
||||
|
||||
joblist = background_scheduler.get_jobs()
|
||||
|
||||
for job in joblist:
|
||||
logging.debug("job:%s,next run time:%s"%(job.id,job.next_run_time))
|
||||
#self._wait_for_unattended_upgrade_finish()
|
||||
'''
|
||||
if FindRuningUnattendedUpgrades():
|
||||
logging.warning("find runing unattended-upgrades,please wait")
|
||||
return False
|
||||
|
@ -877,7 +927,7 @@ class UnattendedUpgradesShutdown():
|
|||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
'''
|
||||
|
||||
def prepare_for_shutdown_handler(active):
|
||||
""" Handle PrepareForShutdown() """
|
||||
|
|
Loading…
Reference in New Issue