From a50005490b0204d012dda76ada95caa43e41ce4b Mon Sep 17 00:00:00 2001 From: shenyafeng Date: Mon, 13 Jun 2022 14:46:39 +0800 Subject: [PATCH] add upgrade randomize time range in system-update.conf --- backend/data/system-updater.conf | 4 +- backend/data/unattended-upgrades-policy.conf | 5 +- unattended-upgrades/kylin-unattended-upgrade | 78 +++++----- .../kylin-unattended-upgrade-shutdown | 133 ++++++++++++------ 4 files changed, 143 insertions(+), 77 deletions(-) diff --git a/backend/data/system-updater.conf b/backend/data/system-updater.conf index 964555e..65e354a 100644 --- a/backend/data/system-updater.conf +++ b/backend/data/system-updater.conf @@ -9,4 +9,6 @@ check_frontend_pkg = True [InstallMode] shutdown_install = False manual_install = False -auto_install = False \ No newline at end of file +auto_install = False +upgradeInterval = 7 +downloadRandom = 180 diff --git a/backend/data/unattended-upgrades-policy.conf b/backend/data/unattended-upgrades-policy.conf index 9c1f235..4569eb6 100644 --- a/backend/data/unattended-upgrades-policy.conf +++ b/backend/data/unattended-upgrades-policy.conf @@ -1,7 +1,6 @@ [autoUpgradePolicy] -preDownload = on -autoUpgradeState = on +preDownload = off +autoUpgradeState = off downloadMode = timing downloadTime = 10:00 installMode = timing -upgradeInverval = 7 diff --git a/unattended-upgrades/kylin-unattended-upgrade b/unattended-upgrades/kylin-unattended-upgrade index 8af140a..d2b0708 100644 --- a/unattended-upgrades/kylin-unattended-upgrade +++ b/unattended-upgrades/kylin-unattended-upgrade @@ -142,7 +142,7 @@ pidfile = None # set from the sigint signal handler SIGNAL_STOP_REQUEST = False -def reload_options_config(self): +def reload_options_config(): #添加默认保留旧配置 apt_pkg.config["DPkg::Options::"] = "--force-confold" options_new = list(set(apt_pkg.config.value_list("DPkg::Options"))) @@ -153,6 +153,13 @@ def reload_options_config(self): apt_pkg.config.clear("DPkg::Options") for option in options_new: apt_pkg.config["DPkg::Options::"] = option + #去除安装推荐和建议的软件包 + if apt_pkg.config.find_b("APT::Install-Recommends",False) == True: + apt_pkg.config.clear("APT::Install-Recommends") + if apt_pkg.config.find_b("APT::Install-Suggests",False) == True: + apt_pkg.config.clear("APT::Install-Suggests") + + apt_pkg.init_system() def get_default_version(): version = "" @@ -457,16 +464,16 @@ class KylinSystemUpdater: def update_detect_finished_handler(success,updatelist,error_status,error_cause): if success: logging.info("update detect success,quiting main loop") - if 'auto-upgrade-list' in updatelist: - try: + try: + if os.path.exists(UNATTENDED_UPGRADE_PKG_LIST_FILE_PATH): with open(UNATTENDED_UPGRADE_PKG_LIST_FILE_PATH, "r") as f: row_data = json.load(f) for key in row_data['upgrade_list'].keys(): self.whitelist_with_candidate_version.append((key,row_data['upgrade_list'][key]['new_version'])) for key in row_data['install_list'].keys(): self.whitelist_with_candidate_version.append((key,row_data['install_list'][key]['new_version'])) - except Exception as e: - logging.error(e) + except Exception as e: + logging.error(e) self.loop.quit() else: WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","idle") @@ -617,7 +624,7 @@ PkgFilePin = namedtuple('PkgFilePin', ['id', 'priority']) class UnattendedUpgradesCache(apt.Cache): - def __init__(self, rootdir, whitelist_with_version): + def __init__(self, rootdir, whitelist_with_version,blacklist): self._cached_candidate_pkgnames = set() # type: Set[str] @@ -625,7 +632,7 @@ class UnattendedUpgradesCache(apt.Cache): logging.info(_("Allowed origins are: %s"), ", ".join(self.allowed_origins)) - # self.blacklist = blacklist + self.blacklist = blacklist ''' apt_pkg.config.value_list( "Unattended-Upgrade::Package-Blacklist") @@ -639,7 +646,7 @@ class UnattendedUpgradesCache(apt.Cache): # self.get_white_list_with_version() # self.whitelist = apt_pkg.config.value_list( # "Unattended-Upgrade::Package-Whitelist") - # self.strict_whitelist = False + self.strict_whitelist = False ''' apt_pkg.config.find_b( "Unattended-Upgrade::Package-Whitelist-Strict", False) @@ -872,23 +879,25 @@ class UnattendedUpgradesCache(apt.Cache): """ new_pkgs_to_adjust = [] # List[str] - if not is_pkg_change_allowed(pkg, self.blacklist, self.whitelist, - self.strict_whitelist): - return + # if not is_pkg_change_allowed(pkg, self.blacklist, self.whitelist, + # self.strict_whitelist): + # return - if function == apt.package.Package.mark_upgrade \ - and not pkg.is_upgradable: - if not apt_pkg.config.find_b("Unattended-Upgrade::Allow-downgrade", - False): - return - else: - function = apt.package.Package.mark_install + # if function == apt.package.Package.mark_upgrade \ + # and not pkg.is_upgradable: + # if not apt_pkg.config.find_b("Unattended-Upgrade::Allow-downgrade", + # False): + # return + # else: + # function = apt.package.Package.mark_install marking_succeeded = self.call_checked(function, pkg, **kwargs) if not marking_succeeded: logging.error("%s mark failed"%pkg.name) - + + return marking_succeeded + ''' if (not marking_succeeded or not check_changes_for_sanity(self, desired_pkg=pkg)) \ and allow_marking_fallback(): @@ -933,7 +942,7 @@ class UnattendedUpgradesCache(apt.Cache): new_pkg_adjusted = True if new_pkg_adjusted: self.call_adjusted(function, pkg, **kwargs) - + ''' def mark_upgrade_adjusted(self, pkg, **kwargs): self.call_adjusted(apt.package.Package.mark_upgrade, pkg, **kwargs) @@ -2342,6 +2351,7 @@ def calculate_upgradable_pkgs(cache, # type: UnattendedUpgradesCache except NoAllowedOriginError: continue + try_to_upgrade(pkg, pkgs_to_upgrade, cache,pkgname[1]) @@ -2622,8 +2632,8 @@ def main(options, rootdir="/"): ''' if res.success and len(res.pkgs) > 0 and res.result_str == "total_install": logging.info("total install") - with open(TIME_STAMP,'w') as f: - f.write(time.time()) + # with open(TIME_STAMP,'w') as f: + # f.write(time.time()) kylin_system_updater.SetConfigValue("SYSTEM","os_version",release) kylin_system_updater.SetConfigValue("SYSTEM","update_version",original_version) else: @@ -2845,7 +2855,7 @@ def run(options, # type: Options # get_white_list_with_version(white_list_with_version,namelist_with_version,namelist) # get a cache try: - cache = UnattendedUpgradesCache(rootdir=rootdir,whitelist_with_version=white_list_with_version) + cache = UnattendedUpgradesCache(rootdir=rootdir,whitelist_with_version=white_list_with_version,blacklist=[]) #cache.whitelist=white_list except SystemError as error: # print(_("Apt returned an error, exiting")) @@ -2889,11 +2899,13 @@ def run(options, # type: Options #adjust candidate versions logging.info("adjusting candidate from kylin update manager...") adjust_candidate_with_version(cache,white_list_with_version) + #sanity check + # download what looks good mark_pkgs_to_upgrade(cache, pkgs) if options.debug: - fetcher = apt_pkg.Acquire(apt.progress.text.AcquireProgress(outfile = logfile_fd)) + fetcher = apt_pkg.Acquire(apt.progress.text.AcquireProgress()) else: fetcher = apt_pkg.Acquire() list = apt_pkg.SourceList() @@ -3040,8 +3052,8 @@ def run(options, # type: Options subprocess.Popen('dbus-send --system --type=signal / com.kylin.update.notification.DownloadFinish', shell=True) kylin_system_updater.SetConfigValue('InstallMode','auto_install','True') elif insmod == 'bshutdown': - logging.info("pkg number:%d,shutdown delay time:%d s"%(len(pkgs),30*len(pkgs))) - login_manager.SetExtraInhibitShutdownDelaySec(30*len(pkgs)) + # logging.info("pkg number:%d,shutdown delay time:%d s"%(len(pkgs),30*len(pkgs))) + login_manager.SetExtraInhibitShutdownDelaySec(1800) configfilemanager.AddFileName("OTA_PKGS_TO_INSTALL") kylin_system_updater.SetConfigValue('InstallMode','auto_install','True') elif insmod == 'timing': @@ -3370,7 +3382,9 @@ if __name__ == "__main__": # set debconf to NON_INTERACTIVE os.environ["DEBIAN_FRONTEND"] = "noninteractive" - + apt_pkg.init_config() + #remove sources in sources.list.d from indexes search + apt_pkg.config.set("Dir::Etc::sourceparts", "") # this ensures the commandline is logged in /var/log/apt/history.log apt_pkg.config.set("Commandline::AsString", " ".join(sys.argv)) @@ -3487,11 +3501,10 @@ if __name__ == "__main__": logging.warning("control center running ,exiting...") sys.exit(1) ''' - - if options.download_only: - kylin_system_updater.ConnectToSignals() - kylin_system_updater.UpdateDetect() - kylin_system_updater.RunMainloop() + kylin_system_updater.ConnectToSignals() + kylin_system_updater.UpdateDetect() + kylin_system_updater.RunMainloop() + if options.download_only: WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","download") elif options.install_only: WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","preinstall") @@ -3508,4 +3521,5 @@ if __name__ == "__main__": ret = subprocess.run("dpkg --configure -a",shell=True,stdout=open(logfile,'a+'),stderr=open(logfile,'a+')) logging.info("dpkg fix return :%s"%ret.returncode) ''' + sys.exit(main(options)) diff --git a/unattended-upgrades/kylin-unattended-upgrade-shutdown b/unattended-upgrades/kylin-unattended-upgrade-shutdown index 0ece50c..878b8bc 100644 --- a/unattended-upgrades/kylin-unattended-upgrade-shutdown +++ b/unattended-upgrades/kylin-unattended-upgrade-shutdown @@ -106,6 +106,7 @@ class TimeElement(IntEnum): UNATTENDED_UPGRADE_CONFIG_FILE_PATH="/var/lib/unattended-upgrades/unattended-upgrade.conf" UNATTENDED_UPGRADE_POLICY_FILE_PATH="/var/lib/unattended-upgrades/unattended-upgrades-policy.conf" NOTIFICATION_PIPE = '/tmp/notification.pipe' +UNATTENDED_UPGRADE_TIMESTAMP = "/var/lib/unattended-upgrades/unattended-upgrades-timestamp" flag_file_list = ["/var/lib/unattended-upgrades/OTA_PKGS_TO_INSTALL",\ "/var/lib/kylin-auto-upgrade/kylin-autoupgrade.conf","/tmp/notify.pid"] @@ -121,6 +122,13 @@ def reload_options_config(): apt_pkg.config.clear("DPkg::Options") for option in options_new: apt_pkg.config["DPkg::Options::"] = option + #去除安装推荐和建议的软件包 + if apt_pkg.config.find_b("APT::Install-Recommends",False) == True: + apt_pkg.config.clear("APT::Install-Recommends") + if apt_pkg.config.find_b("APT::Install-Suggests",False) == True: + apt_pkg.config.clear("APT::Install-Suggests") + + apt_pkg.init_system() def is_dpkg_journal_dirty(): # type: () -> bool @@ -177,7 +185,7 @@ def ReadValueFromFile(file,section,option): config.read(file) value = config[section][option] except Exception as e: - return None + return '' return value def WriteValueToFile(file,section,option,value): @@ -307,7 +315,19 @@ class TimerThread(threading.Thread): def run(self): self.scheduler.start() +class KylinSystemUpdater: + def __init__(self) -> None: + DBusGMainLoop(set_as_default=True) + self.loop = GLib.MainLoop() + self.system_bus = dbus.SystemBus() + self.update_proxy = self.system_bus.get_object('com.kylin.systemupgrade','/com/kylin/systemupgrade') + self.update_interface = dbus.Interface(self.update_proxy,dbus_interface='com.kylin.systemupgrade.interface') + def GetConfigValue(self,section,value): + return self.update_interface.GetConfigValue(section,value) + + def SetConfigValue(self,section,option,value): + return self.update_interface.SetConfigValue(section,option,value) class UnattendedUpgradesShutdown(): # 加载配置文件 unattended-upgrades-policy.conf @@ -318,6 +338,19 @@ class UnattendedUpgradesShutdown(): 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) download_time = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_DOWNLOAD_TIME) + self.download_random = int(kylin_system_updater.GetConfigValue('InstallMode','downloadRandom')[1]) + self.upgrade_interval = int(kylin_system_updater.GetConfigValue('InstallMode','upgradeInterval')[1]) + logging.info("download random:%s,upgrade interval:%s"%(self.download_random,self.upgrade_interval)) + # upgradeInterval = int(ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, 'upgradeInverval')) + if os_release_info['PROJECT_CODENAME'] == 'V10SP1-edu' and os_release_info['SUB_PROJECT_CODENAME']=='mavis': + self.download_time['h'] = 10 + self.download_time['m'] = 0 + self.download_time_r = convert_time_by_random(self.download_time, 5) + logging.debug("upgrade time: [%d] [%d] predown[%s] autoupgrade[%s] d-mode[%s] i-mode[%s]", + self.download_time_r['h'], self.download_time_r['m'],self.preDownload, self.autoUpgrade, \ + self.download_mode, self.install_mode) + return + timelist = download_time.strip().split(':') if len(timelist) != TimeElement.TIME_NUM: logging.debug("unattended-upgrades-policy.conf time err %s",download_time) @@ -336,7 +369,7 @@ class UnattendedUpgradesShutdown(): self.download_time['h'] = tmphour self.download_time['m'] = tmpminute - self.download_time_r = convert_time_by_random(self.download_time, DOWNLOAD_RANDOM) + self.download_time_r = convert_time_by_random(self.download_time, self.download_random) 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) @@ -366,19 +399,20 @@ class UnattendedUpgradesShutdown(): self.install_time = {'h':12, 'm':0} #定时安装时间 12:00 self.download_time_r = convert_time_by_random(self.download_time, DOWNLOAD_RANDOM) #随机化定时下载时间 self.install_time_r = convert_time_by_random(self.install_time, INSTALL_RANDOM) #随机化定时安装时间 - self.preDownload = False #预下载开关 - self.autoUpgrade = True #自动更新开关 + self.preDownload = 'off' #预下载开关 + self.autoUpgrade = 'off' #自动更新开关 self.download_job = None self.install_job = None self.startup_download_job = None self.scheduler = BlockingScheduler() - + try: hasattr(GLib, "MainLoop") DBusGMainLoop(set_as_default=True) except NameError: logging.error("DBusGMainLoop error") pass + try: self.inhibit_lock = self.get_inhibit_shutdown_lock() except dbus.exceptions.DBusException: @@ -548,13 +582,13 @@ class UnattendedUpgradesShutdown(): def run(self): """ delay shutdown and wait for PrepareForShutdown or other signals""" - if os_release_info['PROJECT_CODENAME'] == 'V10SP1-edu' and os_release_info['SUB_PROJECT_CODENAME']=='mavis': - pass - elif time.time() - float(time_stamp) < float(upgrade_interval): - time_str1 = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(float(time_stamp))) - time_str2 = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) - logging.info("upgrade interval not satisfied:%s-%s"%(time_str1,time_str2)) - return 0 + # if os_release_info['PROJECT_CODENAME'] == 'V10SP1-edu' and os_release_info['SUB_PROJECT_CODENAME']=='mavis': + # pass + # elif time.time() - float(time_stamp) < float(upgrade_interval): + # time_str1 = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(float(time_stamp))) + # time_str2 = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) + # logging.info("upgrade interval not satisfied:%s-%s"%(time_str1,time_str2)) + # return 0 # set signal handlers def signal_handler(signum, frame): @@ -580,12 +614,28 @@ class UnattendedUpgradesShutdown(): if self.options.wait_for_signal: def change_upgrade_policy_handler(): if os.path.isfile(UNATTENDED_UPGRADE_POLICY_FILE_PATH): - download_mode = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_DOWNLOAD_MODE) - install_mode = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_INSTALL_MODE) - preDownload = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_PREDOWNLOAD) - autoUpgrade = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_AUTOUPGRADE) - - if autoUpgrade == FeatureSwitch.ON.value and preDownload == FeatureSwitch.ON.value and download_mode ==DownloadMode.TIMING_DOWNLOAD.value: #open download timing + 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) + self.autoUpgrade = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_AUTOUPGRADE) + self.download_random = int(kylin_system_updater.GetConfigValue('InstallMode','downloadRandom')[1]) + self.upgrade_interval = int(kylin_system_updater.GetConfigValue('InstallMode','upgradeInterval')[1]) + logging.info("download random:%d,upgrade interval:%d"%(self.download_random,self.upgrade_interval)) + if self.autoUpgrade == FeatureSwitch.OFF.value: + logging.info("auto upgrade turned off,removing download and instal jobs...") + try: + if self.download_job is not None: + self.download_job.remove() + except Exception as e: + logging.error(e) + try: + if self.install_job is not None: + self.install_job.remove() + except Exception as e: + logging.error(e) + return + + if self.preDownload == FeatureSwitch.ON.value: #open download timing download_time_tmp = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_DOWNLOAD_TIME) timelist = download_time_tmp.split(':') if len(timelist) != TimeElement.TIME_NUM: @@ -598,27 +648,27 @@ class UnattendedUpgradesShutdown(): logging.debug("unattended-upgrades-policy.conf download_time h error") else: self.download_time['h'] = tmphour - try: tmpminute = int(timelist[TimeElement.TIME_MINUTE]) except ValueError: logging.debug("unattended-upgrades-policy.conf download_time m error") else: self.download_time['m'] = tmpminute - - self.download_time_r = convert_time_by_random(self.download_time, DOWNLOAD_RANDOM) + self.download_time_r = convert_time_by_random(self.download_time, self.download_random) try: if self.download_job is not None: self.download_job.remove() except Exception as e: logging.error(e) + logging.info("pre-download time:%d:%d"%(self.download_time_r['h'], self.download_time_r['m'])) self.download_job = self.scheduler.add_job(self.timing_download, 'cron', hour=self.download_time_r['h'], minute=self.download_time_r['m']) else: #close download timing try: self.download_job.pause() except Exception as e: logging.error(e) - if autoUpgrade == FeatureSwitch.ON.value and install_mode == InstallMode.TIMING_INSTALL.value: #open install timing + + if self.install_mode == InstallMode.TIMING_INSTALL.value: #open install timing 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) @@ -627,27 +677,23 @@ class UnattendedUpgradesShutdown(): self.install_job.remove() except Exception as e: logging.error(e) + logging.info("install time:%d:%d"%(self.install_time_r['h'], self.install_time_r['m'])) self.install_job = self.scheduler.add_job(self.timing_install, 'cron', hour=self.install_time_r['h'], minute=self.install_time_r['m']) - elif install_mode == InstallMode.BEFORE_SHUTDOWN_INSTALL.value: - try: - if self.install_job is not None: - self.install_job.remove() - except Exception as e: - logging.error(e) - else: #close install timing - try: - self.install_job.pause() - except Exception as e: - logging.error(e) - if self.install_mode == InstallMode.BEFORE_SHUTDOWN_INSTALL.value: + elif self.install_mode == InstallMode.BEFORE_SHUTDOWN_INSTALL.value: try: if self.install_job is not None: self.install_job.remove() except Exception as e: logging.error(e) logging.debug("install job removed,installation will conduct before shutdown") + else: #close install timing + try: + self.install_job.pause() + except Exception as e: + logging.error(e) - logging.debug("upgrade time: [%d:%d] [%d:%d] predown[%s] autoupgrade[%s] d-mode[%s] i-mode[%s]", + + 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) @@ -728,15 +774,19 @@ class UnattendedUpgradesShutdown(): "now") self.start_iterations() - logging.debug("download time:[%d:%d] install time:[%d:%d]", self.download_time_r['h'], self.download_time_r['m'],self.install_time_r['h'],self.install_time_r['m']) - self.download_job = self.scheduler.add_job(self.timing_download, 'cron', hour=self.download_time_r['h'], minute=self.download_time_r['m']) if os_release_info['PROJECT_CODENAME'] == 'V10SP1-edu' and os_release_info['SUB_PROJECT_CODENAME']=='mavis': logging.info("setting startup download timer") GLib.timeout_add(300*1000, lambda: self.timing_download() and False) #local_time =time.localtime(time.time()+300) - #self.startup_download_job = self.scheduler.add_job(self.timing_download,'cron',hour=local_time.tm_hour,minute = local_time.tm_min) + self.startup_download_job = self.scheduler.add_job(self.timing_download,'cron',hour=self.download_time_r['h'],minute = self.download_time_r['m']) else: - self.install_job = self.scheduler.add_job(self.timing_install, 'cron', hour=self.install_time_r['h'], minute=self.install_time_r['m']) + if self.autoUpgrade == FeatureSwitch.ON.value: + logging.debug("download time:[%d:%d] install time:[%d:%d]", self.download_time_r['h'], self.download_time_r['m'],self.install_time_r['h'],self.install_time_r['m']) + self.download_job = self.scheduler.add_job(self.timing_download, 'cron', hour=self.download_time_r['h'], minute=self.download_time_r['m']) + self.install_job = self.scheduler.add_job(self.timing_install, 'cron', hour=self.install_time_r['h'], minute=self.install_time_r['m']) + elif self.autoUpgrade == FeatureSwitch.OFF.value: + logging.info("auto upgrade turned off") + TimerThread(self.scheduler).start() self.mainloop.run() logging.info("quit mainloop") @@ -939,7 +989,7 @@ if __name__ == "__main__": os_release_info = ReadOsRelease('/etc/os-release') logging.info("project id:%s,sub-project id:%s"%(os_release_info['PROJECT_CODENAME'],os_release_info['SUB_PROJECT_CODENAME'])) - upgrade_interval = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_UPGRADE_INTERVAL) + time_stamp = "0" if os.path.exists(TIME_STAMP): with open(TIME_STAMP,'r') as f: @@ -955,7 +1005,7 @@ if __name__ == "__main__": # easy to get syslog killed try: - apt_pkg.init_config() + # apt_pkg.init_config() reload_options_config() # logdir = apt_pkg.config.find_dir( # "Unattended-Upgrade::LogDir", logdir) @@ -977,5 +1027,6 @@ if __name__ == "__main__": dpkg_fix = subprocess.run("dpkg --configure -a",shell=True,stdout=open(logfile,'a+'),stderr=open(logfile,'a+')) if abnormal_pkg_count != '0': apt_fix = subprocess.run("echo y|apt install -f",shell=True,stdout=open(logfile,'a+'),stderr=open(logfile,'a+')) + kylin_system_updater = KylinSystemUpdater() UnattendedUpgradesShutdown(options).run() #main()