add dpkg confold in uu-shutdown
This commit is contained in:
parent
b31fa7cb0d
commit
d8b8cdd034
|
@ -133,6 +133,8 @@ PID_FILE = "/var/run/unattended-upgrades.pid"
|
|||
LOCK_FILE = "/var/run/kylin-unattended-upgrade.lock"
|
||||
NOTIFICATION_PIPE = '/tmp/notification.pipe'
|
||||
TIME_STAMP = "/var/lib/unattended-upgrades/unattended-upgrades-timestamp"
|
||||
UNATTENDED_UPGRADE_PKG_LIST_FILE_PATH="/var/lib/kylin-system-updater/json/auto-upgrade-list.json"
|
||||
|
||||
# 禁止关机锁文件路径
|
||||
FILELOCK_PATH = "/tmp/lock/"
|
||||
SHUTDOWN_BLOCK_FILELOCK = "kylin-update.lock"
|
||||
|
@ -140,6 +142,18 @@ pidfile = None
|
|||
# set from the sigint signal handler
|
||||
SIGNAL_STOP_REQUEST = False
|
||||
|
||||
def reload_options_config(self):
|
||||
#添加默认保留旧配置
|
||||
apt_pkg.config["DPkg::Options::"] = "--force-confold"
|
||||
options_new = list(set(apt_pkg.config.value_list("DPkg::Options")))
|
||||
for option in ("--force-confnew","--force-confdef"):
|
||||
if option in options_new:
|
||||
options_new.remove(option)
|
||||
#清除所有配置重新加载
|
||||
apt_pkg.config.clear("DPkg::Options")
|
||||
for option in options_new:
|
||||
apt_pkg.config["DPkg::Options::"] = option
|
||||
|
||||
def get_default_version():
|
||||
version = ""
|
||||
INPUT_CONFIG_PATH = '/usr/share/kylin-update-desktop-config/data/kylin-update-desktop-system.json'
|
||||
|
@ -411,7 +425,8 @@ class KylinSystemUpdater:
|
|||
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')
|
||||
self.success = False
|
||||
|
||||
self.whitelist_with_candidate_version = []
|
||||
|
||||
def DataBackendCollect(self,updateinfo,json_file):
|
||||
self.update_interface.DataBackendCollect(updateinfo,json_file)
|
||||
|
||||
|
@ -421,7 +436,7 @@ class KylinSystemUpdater:
|
|||
def SetConfigValue(self,section,option,value):
|
||||
return self.update_interface.SetConfigValue(section,option,value)
|
||||
|
||||
def GetWhiteList(self):
|
||||
def UpdateDetect(self):
|
||||
ret = self.update_interface.UpdateDetect()
|
||||
return ret
|
||||
|
||||
|
@ -439,10 +454,20 @@ 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:
|
||||
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)
|
||||
self.loop.quit()
|
||||
else:
|
||||
WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","idle")
|
||||
logging.error("update detect failed")
|
||||
logging.error("update detect failed:%s,%s"%(error_status,error_cause))
|
||||
os._exit(0)
|
||||
return success
|
||||
|
||||
|
@ -589,7 +614,7 @@ PkgFilePin = namedtuple('PkgFilePin', ['id', 'priority'])
|
|||
|
||||
class UnattendedUpgradesCache(apt.Cache):
|
||||
|
||||
def __init__(self, rootdir, whitelist_with_version,blacklist):
|
||||
def __init__(self, rootdir, whitelist_with_version):
|
||||
|
||||
self._cached_candidate_pkgnames = set() # type: Set[str]
|
||||
|
||||
|
@ -597,13 +622,13 @@ 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")
|
||||
'''
|
||||
logging.info(_("Initial blacklist: %s"), " ".join(self.blacklist))
|
||||
|
||||
# logging.info(_("Initial blacklist: %s"), " ".join(self.blacklist))
|
||||
logging.info("pkg list with version:",whitelist_with_version)
|
||||
self.whitelist_with_version = whitelist_with_version
|
||||
self.whitelist = []
|
||||
self.get_white_list()
|
||||
|
@ -611,22 +636,22 @@ 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)
|
||||
'''
|
||||
logging.info(_("Initial whitelist (%s): %s"),
|
||||
"strict" if self.strict_whitelist else "not strict",
|
||||
" ".join(self.whitelist))
|
||||
# logging.info(_("Initial whitelist (%s): %s"),
|
||||
# "strict" if self.strict_whitelist else "not strict",
|
||||
# " ".join(self.whitelist))
|
||||
apt.Cache.__init__(self, rootdir=rootdir)
|
||||
|
||||
# pre-heat lazy-loaded modules to avoid crash on python upgrade
|
||||
datetime.datetime.strptime("", "")
|
||||
# datetime.datetime.strptime("", "")
|
||||
|
||||
# generate versioned_kernel_pkgs_regexp for later use
|
||||
self.versioned_kernel_pkgs_regexp = versioned_kernel_pkgs_regexp()
|
||||
self.running_kernel_pkgs_regexp = running_kernel_pkgs_regexp()
|
||||
# self.versioned_kernel_pkgs_regexp = versioned_kernel_pkgs_regexp()
|
||||
# self.running_kernel_pkgs_regexp = running_kernel_pkgs_regexp()
|
||||
'''
|
||||
if self.versioned_kernel_pkgs_regexp:
|
||||
logging.debug("Using %s regexp to find kernel packages",
|
||||
|
@ -956,7 +981,7 @@ class LogInstallProgress(apt.progress.base.InstallProgress):
|
|||
UpdateInfos.update({"status":1})
|
||||
json_file = json.dumps(UpdateInfos.copy())
|
||||
UpdateInfos.clear()
|
||||
self.update_interface.DataBackendCollect("UpdateInfos",json_file)
|
||||
kylin_system_updater.DataBackendCollect("UpdateInfos",json_file)
|
||||
|
||||
def error(self,pkg, errormsg):
|
||||
UpdateInfos = {}
|
||||
|
@ -2803,15 +2828,15 @@ def run(options, # type: Options
|
|||
logging.warning(_("dpkg --configure -a output:\n%s"), output)
|
||||
'''
|
||||
|
||||
white_list_with_version = config_manager.ReadListFromFile(WHITE_LIST_FILE_PATH,'AutoUpgrade','upgradelist')
|
||||
logging.debug("whitelist from kylin system updater:%s"%("\n".join(white_list_with_version)))
|
||||
namelist = []
|
||||
namelist_with_version = []
|
||||
blacklist = []
|
||||
get_white_list_with_version(white_list_with_version,namelist_with_version,namelist)
|
||||
white_list_with_version = kylin_system_updater.whitelist_with_candidate_version#config_manager.ReadListFromFile(WHITE_LIST_FILE_PATH,'AutoUpgrade','upgradelist')
|
||||
# logging.debug("whitelist from kylin system updater:%s"%("\n".join(white_list_with_version)))
|
||||
# namelist = []
|
||||
# namelist_with_version = []
|
||||
|
||||
# get_white_list_with_version(white_list_with_version,namelist_with_version,namelist)
|
||||
# get a cache
|
||||
try:
|
||||
cache = UnattendedUpgradesCache(rootdir=rootdir,whitelist_with_version=namelist_with_version,blacklist=blacklist)
|
||||
cache = UnattendedUpgradesCache(rootdir=rootdir,whitelist_with_version=white_list_with_version)
|
||||
#cache.whitelist=white_list
|
||||
except SystemError as error:
|
||||
# print(_("Apt returned an error, exiting"))
|
||||
|
@ -2843,7 +2868,7 @@ def run(options, # type: Options
|
|||
#auto_removable = get_auto_removable(cache)
|
||||
|
||||
# find out about the packages that are upgradable (in an allowed_origin)
|
||||
pkgs_to_upgrade = calculate_upgradable_pkgs(cache, options,namelist_with_version)
|
||||
pkgs_to_upgrade = calculate_upgradable_pkgs(cache, options,white_list_with_version)
|
||||
pkgs_to_upgrade.sort(key=lambda p: p.name)
|
||||
pkgs = [pkg.name for pkg in pkgs_to_upgrade]
|
||||
logging.debug("pkgs that look like they should be upgraded or installed: %s"
|
||||
|
@ -2854,7 +2879,7 @@ def run(options, # type: Options
|
|||
os.nice(old_priority - os.nice(0))
|
||||
#adjust candidate versions
|
||||
logging.info("adjusting candidate from kylin update manager...")
|
||||
adjust_candidate_with_version(cache,namelist_with_version)
|
||||
adjust_candidate_with_version(cache,white_list_with_version)
|
||||
# download what looks good
|
||||
mark_pkgs_to_upgrade(cache, pkgs)
|
||||
|
||||
|
@ -2948,8 +2973,8 @@ def run(options, # type: Options
|
|||
clean_downloaded_packages(fetcher)
|
||||
kylin_system_updater.CheckRebootRequired("unattended-upgrades")
|
||||
install_result = ''
|
||||
logging.debug("pkg number:%d,pkg in whitelist number:%d"%(len(pkgs),len(namelist_with_version)))
|
||||
if len(pkgs) == len(namelist_with_version):
|
||||
logging.debug("pkg number:%d,pkg in whitelist number:%d"%(len(pkgs),len(white_list_with_version)))
|
||||
if len(pkgs) == len(white_list_with_version):
|
||||
install_result = "total_install"
|
||||
else:
|
||||
install_result = "partial_install"
|
||||
|
@ -3000,8 +3025,8 @@ 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)))
|
||||
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")
|
||||
subprocess.Popen('dbus-send --system --type=signal / com.kylin.update.notification.DownloadFinish', shell=True)
|
||||
kylin_system_updater.SetConfigValue('InstallMode','auto_install','True')
|
||||
|
@ -3456,7 +3481,7 @@ if __name__ == "__main__":
|
|||
|
||||
if options.download_only:
|
||||
kylin_system_updater.ConnectToSignals()
|
||||
kylin_system_updater.GetWhiteList()
|
||||
kylin_system_updater.UpdateDetect()
|
||||
kylin_system_updater.RunMainloop()
|
||||
WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","download")
|
||||
elif options.install_only:
|
||||
|
|
|
@ -81,7 +81,7 @@ AUTO_UPGRADE_POLICY_OPTION_INSTALL_MODE = "installMode"
|
|||
AUTO_UPGRADE_POLICY_OPTION_UPGRADE_INTERVAL = "upgradeInverval"
|
||||
INTERVAL_DOWN_INSTALL = 120 # 下载安装的间隔 分钟
|
||||
INSTALL_RANDOM = 5 # 安装时间随机数范围0-INSTALL_RANDOM 分钟
|
||||
DOWNLOAD_RANDOM = 3 # 下载时间随机数范围0-DOWNLOAD_RANDOM 分钟
|
||||
DOWNLOAD_RANDOM = 180 # 下载时间随机数范围0-DOWNLOAD_RANDOM 分钟
|
||||
|
||||
class FeatureSwitch(Enum):
|
||||
ON = 'on'
|
||||
|
@ -110,6 +110,18 @@ NOTIFICATION_PIPE = '/tmp/notification.pipe'
|
|||
flag_file_list = ["/var/lib/unattended-upgrades/OTA_PKGS_TO_INSTALL",\
|
||||
"/var/lib/kylin-auto-upgrade/kylin-autoupgrade.conf","/tmp/notify.pid"]
|
||||
|
||||
def reload_options_config():
|
||||
#添加默认保留旧配置
|
||||
apt_pkg.config["DPkg::Options::"] = "--force-confold"
|
||||
options_new = list(set(apt_pkg.config.value_list("DPkg::Options")))
|
||||
for option in ("--force-confnew","--force-confdef"):
|
||||
if option in options_new:
|
||||
options_new.remove(option)
|
||||
#清除所有配置重新加载
|
||||
apt_pkg.config.clear("DPkg::Options")
|
||||
for option in options_new:
|
||||
apt_pkg.config["DPkg::Options::"] = option
|
||||
|
||||
def is_dpkg_journal_dirty():
|
||||
# type: () -> bool
|
||||
"""
|
||||
|
@ -926,6 +938,7 @@ if __name__ == "__main__":
|
|||
|
||||
try:
|
||||
apt_pkg.init_config()
|
||||
reload_options_config()
|
||||
# logdir = apt_pkg.config.find_dir(
|
||||
# "Unattended-Upgrade::LogDir", logdir)
|
||||
except apt_pkg.Error as error:
|
||||
|
@ -945,6 +958,6 @@ if __name__ == "__main__":
|
|||
if dpkg_journal_dirty:
|
||||
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.Popen("echo y|apt install -f",shell=True,stdout=open(logfile,'a+'),stderr=open(logfile,'a+'))
|
||||
apt_fix = subprocess.run("echo y|apt install -f",shell=True,stdout=open(logfile,'a+'),stderr=open(logfile,'a+'))
|
||||
UnattendedUpgradesShutdown(options).run()
|
||||
#main()
|
||||
|
|
Loading…
Reference in New Issue