From 456755370af1de8bd74f300c1a2f8d31131eace4 Mon Sep 17 00:00:00 2001 From: shenyafeng Date: Tue, 14 Jun 2022 09:51:12 +0800 Subject: [PATCH 1/3] add progress log --- unattended-upgrades/kylin-unattended-upgrade | 4 ++-- unattended-upgrades/kylin-unattended-upgrade-shutdown | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/unattended-upgrades/kylin-unattended-upgrade b/unattended-upgrades/kylin-unattended-upgrade index d2b0708..32a677e 100644 --- a/unattended-upgrades/kylin-unattended-upgrade +++ b/unattended-upgrades/kylin-unattended-upgrade @@ -3046,13 +3046,13 @@ def run(options, # type: Options logging.info("all pkgs downloaded") else: return UnattendedUpgradesResult(False,_("docker fetch failed")) - # logging.info("pkg number:%d,shutdown delay time:%d s"%(len(pkgs),30*len(pkgs))) + logging.info("pkg number:%d"%(len(pkgs))) login_manager.SetExtraInhibitShutdownDelaySec(1800) configfilemanager.AddFileName("OTA_PKGS_TO_INSTALL") 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))) + logging.info("pkg number:%d"%(len(pkgs))) login_manager.SetExtraInhibitShutdownDelaySec(1800) configfilemanager.AddFileName("OTA_PKGS_TO_INSTALL") kylin_system_updater.SetConfigValue('InstallMode','auto_install','True') diff --git a/unattended-upgrades/kylin-unattended-upgrade-shutdown b/unattended-upgrades/kylin-unattended-upgrade-shutdown index 878b8bc..072755d 100644 --- a/unattended-upgrades/kylin-unattended-upgrade-shutdown +++ b/unattended-upgrades/kylin-unattended-upgrade-shutdown @@ -244,7 +244,7 @@ def log_progress(): "please don't turn off the computer") ''' # progress info - progress_file = "/var/run/kylin-unattended-upgrades.progress" + progress_file = PROGRESS_LOG if os.path.exists(progress_file): progress_text = open(progress_file).read() logging.debug("progress text content %s"%progress_text) From 5046a656e93fd39424d5242f4f75c33ac900bd5c Mon Sep 17 00:00:00 2001 From: shenyafeng Date: Thu, 16 Jun 2022 16:06:14 +0800 Subject: [PATCH 2/3] remove predownload func;get config value from section AutoUpgradeConfig --- unattended-upgrades/kylin-unattended-upgrade | 20 ++- .../kylin-unattended-upgrade-shutdown | 129 ++++++++++++------ 2 files changed, 104 insertions(+), 45 deletions(-) diff --git a/unattended-upgrades/kylin-unattended-upgrade b/unattended-upgrades/kylin-unattended-upgrade index 32a677e..fabe581 100644 --- a/unattended-upgrades/kylin-unattended-upgrade +++ b/unattended-upgrades/kylin-unattended-upgrade @@ -533,10 +533,19 @@ class KylinBackupManager: def ConnectToSignals(self): def backup_start_handler(result): + logging.debug("backup start result:%d"%result) if result == 31 or result == 30: logging.debug("backup start success") else: logging.error("backup start failed") + UpdateInfos = {} + UpdateInfos.update({"packageName":""}) + UpdateInfos.update({"source":"kylin unattended upgrade"}) + UpdateInfos.update({"status":0}) + UpdateInfos.update({"errorCode":"backup start failed"}) + json_file = json.dumps(UpdateInfos.copy()) + UpdateInfos.clear() + kylin_system_updater.DataBackendCollect("UpdateInfos",json_file) WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","idle") os._exit(1) @@ -546,6 +555,14 @@ class KylinBackupManager: self.loop.quit() else: logging.error("backup failed") + UpdateInfos = {} + UpdateInfos.update({"packageName":""}) + UpdateInfos.update({"source":"kylin unattended upgrade"}) + UpdateInfos.update({"status":0}) + UpdateInfos.update({"errorCode":"backup failed"}) + json_file = json.dumps(UpdateInfos.copy()) + UpdateInfos.clear() + kylin_system_updater.DataBackendCollect("UpdateInfos",json_file) WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","idle") subprocess.Popen('dbus-send --system --type=signal / com.kylin.install.notification.BackupFailure',shell=True) os._exit(1) @@ -2657,6 +2674,7 @@ def main(options, rootdir="/"): config_to_result.set("OTA","upgrade","1") if not os.path.exists(OTA_RESULT_FILE_PATH): os.makedirs(OTA_RESULT_FILE_PATH) + if not os.path.exists(OTA_RESULT_FILE): f = open(OTA_RESULT_FILE,'w') f.close() @@ -3038,7 +3056,7 @@ def run(options, # type: Options insmod = ReadValueFromFile("/var/lib/unattended-upgrades/unattended-upgrades-policy.conf","autoUpgradePolicy","installmode") if fetcher_statistics.incomplete_pkg_amount == 0 and len(pkgs_to_upgrade) > 0: if os_release_info['PROJECT_CODENAME'] == 'V10SP1-edu' and os_release_info['SUB_PROJECT_CODENAME']=='mavis': - docker_image_fetch_result = None + docker_image_fetch_result = 0 #docker image fetch for mavis and laika if os.path.exists("/usr/bin/service_runtime_ota.sh"): docker_image_fetch_result = subprocess.run(["/usr/bin/service_runtime_ota.sh"], shell=True) diff --git a/unattended-upgrades/kylin-unattended-upgrade-shutdown b/unattended-upgrades/kylin-unattended-upgrade-shutdown index 072755d..ac44642 100644 --- a/unattended-upgrades/kylin-unattended-upgrade-shutdown +++ b/unattended-upgrades/kylin-unattended-upgrade-shutdown @@ -338,10 +338,11 @@ 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]) + self.download_random = int(kylin_system_updater.GetConfigValue('AutoUpgradeConfig','downloadRandom')[1]) + self.upgrade_interval = int(kylin_system_updater.GetConfigValue('AutoUpgradeConfig','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 @@ -350,7 +351,7 @@ class UnattendedUpgradesShutdown(): 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) @@ -618,22 +619,33 @@ class UnattendedUpgradesShutdown(): 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]) + self.download_random = int(kylin_system_updater.GetConfigValue('AutoUpgradeConfig','downloadRandom')[1]) + self.upgrade_interval = int(kylin_system_updater.GetConfigValue('AutoUpgradeConfig','upgradeInterval')[1]) + download_time = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_DOWNLOAD_TIME) + timelist = download_time.strip().split(':') + if len(timelist) != TimeElement.TIME_NUM: + logging.debug("unattended-upgrades-policy.conf time err %s",download_time) + return + # 检查 传入时间 安全性 + try: + tmphour = int(timelist[TimeElement.TIME_HOUR]) + except ValueError: + logging.debug("unattended-upgrades-policy.conf download_time h error") + return + try: + tmpminute = int(timelist[TimeElement.TIME_MINUTE]) + except ValueError: + logging.debug("unattended-upgrades-policy.conf download_time m error") + return + + self.download_time['h'] = tmphour + self.download_time['m'] = tmpminute + 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) + ''' 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) @@ -662,41 +674,70 @@ class UnattendedUpgradesShutdown(): 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']) + elif self.preDownload == FeatureSwitch.OFF.value: + pass + else: #close download timing try: 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...") + 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 + else: + if self.download_mode == DownloadMode.TIMING_DOWNLOAD.value: + try: + if self.download_job is not None: + self.download_job.remove() + except Exception as e: + logging.error(e) + logging.info("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: + try: + self.download_job.remove() + except Exception as e: + logging.error(e) - 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) - try: - if self.install_job is not None: - 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 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) + if self.install_mode == InstallMode.TIMING_INSTALL.value: + try: + if self.install_job is not None: + 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 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) - - + else: #close install timing + try: + self.install_job.remove() + except Exception as e: + 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) - + ''' else: logging.debug("unattended-upgrades-policy.conf not exist") @@ -732,7 +773,7 @@ class UnattendedUpgradesShutdown(): self.start_iterations() logging.info("finished iteration") elif autoUpgrade == FeatureSwitch.ON.value and self.install_mode == InstallMode.BEFORE_SHUTDOWN_INSTALL.value: - if self.update_interface.GetConfigValue('InstallMode','shutdown_install'): + if self.update_interface.GetConfigValue('AutoUpgradeConfig','shutdown_install'): #show plymouth splash if bsshutdown is set if os.path.exists(PKGS_TO_INSTALL_FLAG_FILE): do_plymouth_splash() From c86a8c8e30b4fa044759b894af868a897ef952ab Mon Sep 17 00:00:00 2001 From: shenyafeng Date: Thu, 16 Jun 2022 17:20:27 +0800 Subject: [PATCH 3/3] check timer job pending before remove ;remove logging when removing timer jobs --- .../kylin-unattended-upgrade-shutdown | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/unattended-upgrades/kylin-unattended-upgrade-shutdown b/unattended-upgrades/kylin-unattended-upgrade-shutdown index ac44642..5a013c3 100644 --- a/unattended-upgrades/kylin-unattended-upgrade-shutdown +++ b/unattended-upgrades/kylin-unattended-upgrade-shutdown @@ -687,51 +687,60 @@ class UnattendedUpgradesShutdown(): 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: + if self.download_job.pending: self.download_job.remove() except Exception as e: - logging.error(e) + pass + # logging.error(e) try: - if self.install_job is not None: + if self.install_job.pending: self.install_job.remove() except Exception as e: - logging.error(e) + pass + # logging.error(e) return else: if self.download_mode == DownloadMode.TIMING_DOWNLOAD.value: try: - if self.download_job is not None: + if self.download_job.pending: self.download_job.remove() except Exception as e: - logging.error(e) + pass + # logging.error(e) logging.info("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: try: - self.download_job.remove() + if self.download_job.pending: + self.download_job.remove() except Exception as e: - logging.error(e) + pass + # logging.error(e) if self.install_mode == InstallMode.TIMING_INSTALL.value: try: - if self.install_job is not None: + if self.install_job.pending: self.install_job.remove() except Exception as e: - logging.error(e) + pass + # 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 self.install_mode == InstallMode.BEFORE_SHUTDOWN_INSTALL.value: try: - if self.install_job is not None: + if self.install_job.pending: self.install_job.remove() except Exception as e: - logging.error(e) + pass + # logging.error(e) logging.debug("install job removed,installation will conduct before shutdown") else: #close install timing try: - self.install_job.remove() + if self.download_job.pending: + self.install_job.remove() except Exception as e: - logging.error(e) + pass + # logging.error(e) ''' logging.info("upgrade time: [%d:%d] [%d:%d] predown[%s] autoupgrade[%s] d-mode[%s] i-mode[%s]", @@ -813,7 +822,7 @@ class UnattendedUpgradesShutdown(): # starting final iterations immediately logging.debug("Skip waiting for signals, starting operation " "now") - self.start_iterations() + # self.start_iterations() if os_release_info['PROJECT_CODENAME'] == 'V10SP1-edu' and os_release_info['SUB_PROJECT_CODENAME']=='mavis': logging.info("setting startup download timer")