Merge branch 'dev' of ssh://172.17.66.163:10022/wangsong/kylin-system-updater into dev

This commit is contained in:
wangsong 2021-10-14 13:40:26 +08:00
commit 9791b16dc7
4 changed files with 61 additions and 2 deletions

View File

@ -4,6 +4,7 @@
import os
import sys
import dbus
import fcntl
import apt_pkg
import logging
import dbus.service
@ -26,6 +27,11 @@ from SystemUpdater.backend import DownloadBackend as downb
#安装完成之后是否有请求需要重启
REBOOT_REQUIRED_FILE = "/var/run/reboot-required"
# 禁止关机锁文件路径
path = "/tmp/lock/"
lockfile = "kylin-update.lock"
pidfile = 0
GROUPS_PKG_NAME = 'kylin-update-desktop-config'
INSTALL_ALONE_PROGRESS = "alone"
@ -136,6 +142,7 @@ class UpdateManager():
logging.info("Disk Check finished...")
try:
self.is_upgrading = True
self.filelock()
install_backend = get_backend(self, InstallBackend.ACTION_INSTALL)
install_backend.start(force_install,partial_upgrade_list=partial_upgrade_list)
except Exception as e:
@ -148,6 +155,7 @@ class UpdateManager():
return
logging.info("Disk Check finished...")
self.is_upgrading = True
self.filelock()
install_backend = get_backend(self, InstallBackend.ACTION_INSTALL)
install_backend.start_alone(pkgs_install,pkgs_upgrade,pkgs_remove,pkgs_purge)
@ -267,6 +275,30 @@ class UpdateManager():
return _success,header,desc
def filelock(self):
global pidfile
if not os.path.exists(path):
os.makedirs(path)
pidfile = open(os.path.join(path, "kylin-update.lock"), "w+")
try:
fcntl.flock(pidfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
logging.info("Has been locked.")
except:
logging.error("file cannot be locked.")
return False
def fileunlock(self):
global pidfile
if not pidfile:
return False
try:
fcntl.flock(pidfile, fcntl.LOCK_UN)
pidfile.close()
logging.info("Has been unlocked.")
except:
logging.error("unlock failed.")
return False
def _setup_dbus(self):
# check if there is another g-a-i already and if not setup one
# listening on dbus
@ -297,4 +329,6 @@ class UpdateManager():
bus_name = dbus.service.BusName(UPDATER_DBUS_SERVICE,
bus)
logging.info(_("initiate dbus success ..."))
return UpdateManagerDbusController(self, bus_name)
return UpdateManagerDbusController(self, bus_name)

View File

@ -213,6 +213,7 @@ class InstallBackend():
self.window_main.dbusController.UpdateDownloadFinished(success,self.now_upgrade_list,error_string,error_desc)
else:
self.window_main.dbusController.UpdateDownloadFinished(success,self.now_upgrade_list,'','')
self.window_main.fileunlock()

13
debian/changelog vendored
View File

@ -1,3 +1,16 @@
kylin-system-updater (1.1.5kord) v101; urgency=medium
* 升级禁止关机
-- luoxueyi <luoxueyi@kylinos.cn> Thu, 14 Oct 2021 11:00:54 +0800
kylin-system-updater (1.1.4kord) v101; urgency=medium
* 代码优化,新增接口.
* 修改数据库结构.
-- luoxueyi <luoxueyi@kylinos.cn> Wed, 29 Sep 2021 17:13:31 +0800
kylin-system-updater (1.1.2kord) v101; urgency=medium
* 增加数据库接口 .

View File

@ -9,17 +9,28 @@ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
import signal
import os
import sys
import fcntl
from SystemUpdater.Core.LogManager import get_logfile as logfile
#定义日志的格式
FORMAT = '%(asctime)-15s %(levelname)s:%(message)s'
FORMAT_DEBUG = '%(asctime)-15s %(levelname)s(%(filename)s:%(lineno)d):%(message)s'
pidfile = 0
def signal_handler_term(signal, frame):
# type: (int, object) -> None
global pidfile
if pidfile:
try:
fcntl.fcntl(pidfile, fcntl.LOCK_UN)
pidfile.close()
logging.info("SIGTERM received,file unlocked")
except:
logging.error("File lock release failure")
logging.warning("SIGTERM received, will stop")
os._exit(1)