add dpkg fix before each run;add startup 5min download in mavis project
This commit is contained in:
parent
57a730e8d5
commit
290194bba4
|
@ -1098,14 +1098,18 @@ def is_dpkg_journal_dirty():
|
|||
Return True if the dpkg journal is dirty
|
||||
(similar to debSystem::CheckUpdates)
|
||||
"""
|
||||
d = os.path.join(
|
||||
os.path.dirname(apt_pkg.config.find_file("Dir::State::status")),
|
||||
logging.debug("checking whether dpkg journal is dirty")
|
||||
d = os.path.join("/var/lib/dpkg/",
|
||||
#os.path.dirname(apt_pkg.config.find_file("Dir::State::status")),
|
||||
"updates")
|
||||
for f in os.listdir(d):
|
||||
if re.match("[0-9]+", f) or re.match("tmp.i", f):
|
||||
if re.match("[0-9]+", f) or re.match("tmp.i",f):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_abnormally_installed_pkg_count():
|
||||
output = subprocess.check_output('dpkg -l|grep ^i[^i]|wc -l',shell=True)
|
||||
return output.decode().strip()
|
||||
|
||||
def signal_handler(signal, frame):
|
||||
# type: (int, object) -> None
|
||||
|
@ -2493,10 +2497,14 @@ def main(options, rootdir="/"):
|
|||
|
||||
# see debian #776752
|
||||
install_start_time = datetime.datetime.now().replace(microsecond=0)
|
||||
|
||||
logging.info("unattended-upgrades start time:%s"%install_start_time)
|
||||
# get log
|
||||
|
||||
|
||||
dpkg_journal_dirty = is_dpkg_journal_dirty()
|
||||
abnormal_pkg_count = get_abnormally_installed_pkg_count()
|
||||
logging.info("abnormal pkg count:%d,dpkg dirty:%s"%(abnormal_pkg_count,dpkg_journal_dirty))
|
||||
if dpkg_journal_dirty and abnormal_pkg_count > 0:
|
||||
ret = subprocess.run(["dpkg", "--force-confold", "--configure", "-a"],shell=True,stdout=open(logfile,'a+'),stderr=open(logfile,'a+'))
|
||||
logging.info("dpkg fix return :%s"%ret.returncode)
|
||||
# lock for the shutdown check
|
||||
# shutdown_lock = apt_pkg.get_lock(LOCK_FILE)
|
||||
# if shutdown_lock < 0:
|
||||
|
|
|
@ -266,7 +266,7 @@ 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)
|
||||
timelist = download_time.split(':')
|
||||
timelist = download_time.strip().split(':')
|
||||
if len(timelist) != TimeElement.TIME_NUM:
|
||||
logging.debug("unattended-upgrades-policy.conf time err %s",download_time)
|
||||
return
|
||||
|
@ -298,6 +298,7 @@ class UnattendedUpgradesShutdown():
|
|||
# type: (Values) -> None
|
||||
self.options = options
|
||||
self.max_delay = options.delay * 60
|
||||
self.mainloop = GLib.MainLoop()
|
||||
self.iter_timer_set = False
|
||||
self.apt_pkg_reinit_done = None
|
||||
self.shutdown_pending = False
|
||||
|
@ -317,6 +318,7 @@ class UnattendedUpgradesShutdown():
|
|||
self.autoUpgrade = True #自动更新开关
|
||||
self.download_job = None
|
||||
self.install_job = None
|
||||
self.startup_download_job = None
|
||||
self.scheduler = BlockingScheduler()
|
||||
|
||||
try:
|
||||
|
@ -461,11 +463,17 @@ class UnattendedUpgradesShutdown():
|
|||
|
||||
|
||||
def _wait_for_unattended_upgrade_finish(self):
|
||||
max_wait_time = 300
|
||||
wait_time = 0
|
||||
#read unattended-upgrade status
|
||||
status = ReadValueFromFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status")
|
||||
while (status != "idle"):
|
||||
ReadValueFromFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status")
|
||||
time.sleep(1)
|
||||
wait_time += 1
|
||||
if wait_time >max_wait_time:
|
||||
logging.info("wait for uu time out")
|
||||
return
|
||||
return 0
|
||||
|
||||
def _pause_timer(self):
|
||||
|
@ -492,7 +500,7 @@ class UnattendedUpgradesShutdown():
|
|||
"SIGTERM or SIGHUP received, stopping unattended-upgrades "
|
||||
"only if it is running")
|
||||
self.stop_signal_received.set()
|
||||
self.start_iterations()
|
||||
#self.start_iterations()
|
||||
|
||||
# fall back to polling without GLib
|
||||
try:
|
||||
|
@ -587,17 +595,24 @@ class UnattendedUpgradesShutdown():
|
|||
if os.path.exists(PKGS_TO_INSTALL_FLAG_FILE):
|
||||
do_plymouth_splash()
|
||||
self.start_iterations()
|
||||
logging.info("finished iteration")
|
||||
self.set_max_inhibit_time(5)
|
||||
logging.debug("quiting mainloop")
|
||||
self.mainloop.quit()
|
||||
else:
|
||||
os._exit(0)
|
||||
self.set_max_inhibit_time(5)
|
||||
self.mainloop.quit()
|
||||
else:
|
||||
os._exit(0)
|
||||
self.set_max_inhibit_time(5)
|
||||
self.mainloop.quit()
|
||||
else:
|
||||
os._exit(0)
|
||||
self.set_max_inhibit_time(5)
|
||||
self.mainloop.quit()
|
||||
self.get_update_proxy()
|
||||
self.get_update_interface()
|
||||
self.update_proxy.connect_to_signal("ChangeUpgradePolicy",change_upgrade_policy_handler)
|
||||
self.update_proxy.connect_to_signal("UpgradeAllNow",upgrade_all_now_handler)
|
||||
self.set_max_inhibit_time(1800)
|
||||
|
||||
try:
|
||||
self.get_logind_proxy().connect_to_signal(
|
||||
"PrepareForShutdown", prepare_for_shutdown_handler)
|
||||
|
@ -609,7 +624,7 @@ class UnattendedUpgradesShutdown():
|
|||
_("Maybe systemd-logind service is not running."))
|
||||
# self.run_polling(signal_handler)
|
||||
return
|
||||
|
||||
self.set_max_inhibit_time(1800)
|
||||
logging.debug("Waiting for signal to start operation ")
|
||||
else:
|
||||
# starting final iterations immediately
|
||||
|
@ -618,17 +633,17 @@ class UnattendedUpgradesShutdown():
|
|||
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'])
|
||||
logging.info("project id:%s,sub-project id:%s"%(os_release_info['PROJECT_CODENAME'],os_release_info['SUB_PROJECT_CODENAME']))
|
||||
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("mavis project")
|
||||
logging.info("setting download timer")
|
||||
t = threading.Timer(300,self.timing_download)
|
||||
t.start()
|
||||
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)
|
||||
else:
|
||||
self.install_job = self.scheduler.add_job(self.timing_install, 'cron', hour=self.install_time_r['h'], minute=self.install_time_r['m'])
|
||||
TimerThread(self.scheduler).start()
|
||||
GLib.MainLoop().run()
|
||||
self.mainloop.run()
|
||||
logging.info("quit mainloop")
|
||||
#GLib.MainLoop().run()
|
||||
|
||||
def try_iter_on_shutdown(self):
|
||||
# check if we need to run unattended-upgrades on shutdown and if
|
||||
|
@ -733,7 +748,7 @@ def main():
|
|||
parser.add_option("", "--debug",
|
||||
action="store_true", dest="debug",
|
||||
default=apt_pkg.config.find_b(
|
||||
"Unattended-Upgrade::Debug", False),
|
||||
"Unattended-Upgrade::Debug", True),
|
||||
help="print debug messages")
|
||||
parser.add_option("", "--delay", default=25, type="int",
|
||||
help="delay in minutes to wait for unattended-upgrades")
|
||||
|
@ -770,4 +785,5 @@ def main():
|
|||
|
||||
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']))
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue