Merge branch 'uu_test' into 'backend_uu'
release dpkg lock before each cache commit See merge request kylin-desktop/update-manager-group/kylin-system-updater!470
This commit is contained in:
commit
e81b51dd04
|
@ -22,16 +22,18 @@
|
|||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#from backend.build.lib.SystemUpdater.backend.DownloadBackend import FetchProgress
|
||||
from email.policy import default
|
||||
# from email.policy import default
|
||||
import stat
|
||||
import atexit
|
||||
import copy
|
||||
import datetime
|
||||
import errno
|
||||
import email.charset
|
||||
# import email.charset
|
||||
import fcntl
|
||||
import fnmatch
|
||||
import gettext
|
||||
|
||||
# from backend.SystemUpdater.Core.utils import error
|
||||
#from zoneinfo import ZoneInfoNotFoundError
|
||||
'''
|
||||
try:
|
||||
|
@ -71,6 +73,7 @@ except ImportError:
|
|||
from collections import defaultdict, namedtuple
|
||||
from datetime import date
|
||||
from email.message import Message
|
||||
import email
|
||||
from gettext import gettext as _
|
||||
from io import StringIO
|
||||
from optparse import (
|
||||
|
@ -1470,7 +1473,8 @@ def cache_commit(cache, # type: apt.Cache
|
|||
if iprogress is None:
|
||||
iprogress = LogInstallProgress(logfile_dpkg, verbose,progress_log=PROGRESS_LOG)
|
||||
try:
|
||||
res = cache.commit(fetch_progress=None,install_progress=iprogress,allow_unauthenticated=True)
|
||||
with Unlocked():
|
||||
res = cache.commit(fetch_progress=None,install_progress=iprogress,allow_unauthenticated=True)
|
||||
#cache.open()
|
||||
except SystemError as e:
|
||||
error = e
|
||||
|
@ -2159,7 +2163,7 @@ def do_install(cache, # type: UnattendedUpgradesCache
|
|||
try:
|
||||
pkg_install_success = cache.commit(fetch_progress=apt.progress.text.AcquireProgress(outfile = logfile_fd),install_progress=iprogress,allow_unauthenticated=True)
|
||||
except Exception as e:
|
||||
logging.error("cache commit errot:%s"%e)
|
||||
logging.error("cache commit error:%s"%e)
|
||||
|
||||
'''
|
||||
try:
|
||||
|
@ -2654,14 +2658,15 @@ def main(options, rootdir="/"):
|
|||
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:
|
||||
# uu_lock = apt_pkg.get_lock(LOCK_FILE)
|
||||
# if uu_lock < 0:
|
||||
# logging.error("Lock file is already taken, exiting")
|
||||
# WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","idle")
|
||||
# return 1
|
||||
|
||||
try:
|
||||
res = run(options, rootdir, logfile_dpkg)
|
||||
|
||||
release = ''
|
||||
version = ''
|
||||
original_version = ''
|
||||
|
@ -2768,8 +2773,8 @@ def main(options, rootdir="/"):
|
|||
# os.chmod(OTA_RESULT_FILE,stat.S_IRUSR|stat.S_IWUSR|stat.S_IWGRP|stat.S_IRGRP|stat.S_IWOTH|stat.S_IROTH)
|
||||
# os.chmod(OTA_RESULT_FILE,stat.S_IRWXU|stat.S_IRWXG|stat.S_IRWXO)
|
||||
|
||||
|
||||
WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","idle")
|
||||
|
||||
# WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","idle")
|
||||
'''
|
||||
if res.success and res.result_str:
|
||||
# complete, successful run
|
||||
|
@ -2913,14 +2918,14 @@ def run(options, # type: Options
|
|||
kylin_system_updater.RunMainloop()
|
||||
'''
|
||||
# check and get lock
|
||||
try:
|
||||
apt_pkg.pkgsystem_lock()
|
||||
except SystemError:
|
||||
logging.error(_("Lock could not be acquired (another package "
|
||||
"manager running?)"))
|
||||
#print(_("Cache lock can not be acquired, exiting"))
|
||||
return UnattendedUpgradesResult(
|
||||
False, _("Lock could not be acquired"))
|
||||
# try:
|
||||
# apt_pkg.pkgsystem_lock()
|
||||
# except SystemError:
|
||||
# logging.error(_("Lock could not be acquired (another package "
|
||||
# "manager running?)"))
|
||||
# #print(_("Cache lock can not be acquired, exiting"))
|
||||
# return UnattendedUpgradesResult(
|
||||
# False, _("Lock could not be acquired"))
|
||||
|
||||
# check if the journal is dirty and if so, take emergceny action
|
||||
# the alternative is to leave the system potentially unsecure until
|
||||
|
@ -3100,6 +3105,7 @@ def run(options, # type: Options
|
|||
pkgs,
|
||||
options,
|
||||
logfile_dpkg)
|
||||
|
||||
unLockedEnableShutdown()
|
||||
subprocess.Popen('dbus-send --system --type=signal / com.kylin.install.notification.InstallFinish',shell=True)
|
||||
if pkg_install_success:
|
||||
|
@ -3570,7 +3576,8 @@ if __name__ == "__main__":
|
|||
fp.write("%s" % os.getpid())
|
||||
atexit.register(os.remove, PID_FILE)
|
||||
#setup log dir
|
||||
logdir = os.path.join("var", "log", "kylin-unattended-upgrades")
|
||||
# logdir = os.path.join("var", "log", "kylin-unattended-upgrades")
|
||||
logdir = "/var/log/kylin-unattended-upgrades"
|
||||
if not os.path.exists(logdir):
|
||||
os.makedirs(logdir)
|
||||
#setup log
|
||||
|
|
|
@ -1073,8 +1073,7 @@ if __name__ == "__main__":
|
|||
dpkg_fix=None
|
||||
if os_release_info['PROJECT_CODENAME'] == 'V10SP1-edu' and os_release_info['SUB_PROJECT_CODENAME']=='mavis':
|
||||
dpkg_journal_dirty = is_dpkg_journal_dirty()
|
||||
abnormal_pkg_count = get_abnormally_installed_pkg_count()
|
||||
logging.info("abnormal pkg count:%s,dpkg dirty:%s"%(abnormal_pkg_count,dpkg_journal_dirty))
|
||||
logging.info("dpkg dirty:%s"%(dpkg_journal_dirty))
|
||||
if dpkg_journal_dirty:
|
||||
try:
|
||||
with open(OTA_PKGS_TO_INSTALL_LIST,'r') as f:
|
||||
|
@ -1083,6 +1082,8 @@ if __name__ == "__main__":
|
|||
except Exception as e:
|
||||
logging.error(e)
|
||||
# dpkg_fix = subprocess.run("dpkg --configure -a",shell=True,stdout=open(logfile,'a+'),stderr=open(logfile,'a+'))
|
||||
abnormal_pkg_count = get_abnormally_installed_pkg_count()
|
||||
logging.info("abnormal pkg count:%s"%(abnormal_pkg_count))
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue