Merge branch 'dev' of ssh://172.17.66.163:10022/wangsong/kylin-system-updater into dev
This commit is contained in:
commit
302b8516be
|
@ -39,6 +39,7 @@ import os
|
|||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import fcntl
|
||||
from urllib.request import (
|
||||
ProxyHandler,
|
||||
Request,
|
||||
|
@ -50,6 +51,10 @@ from urllib.parse import urlsplit
|
|||
|
||||
from copy import copy
|
||||
|
||||
# 禁止关机锁文件路径
|
||||
FILELOCK_PATH = "/tmp/lock/"
|
||||
SHUTDOWN_BLOCK_FILELOCK = "kylin-update.lock"
|
||||
pidfile = 0
|
||||
|
||||
class ExecutionTime(object):
|
||||
"""
|
||||
|
@ -559,6 +564,29 @@ def get_package_label(pkg):
|
|||
name = getattr(pkg.candidate, "summary", "")
|
||||
return capitalize_first_word(name)
|
||||
|
||||
def LockedPreventShutdown():
|
||||
global pidfile
|
||||
if not os.path.exists(FILELOCK_PATH):
|
||||
os.makedirs(FILELOCK_PATH)
|
||||
pidfile = open(os.path.join(FILELOCK_PATH, SHUTDOWN_BLOCK_FILELOCK), "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 unLockedEnableShutdown():
|
||||
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
|
||||
|
||||
if __name__ == "__main__":
|
||||
#print(mirror_from_sources_list())
|
||||
|
|
|
@ -23,15 +23,13 @@ from .Core.loop import mainloop
|
|||
import time
|
||||
from gettext import gettext as _
|
||||
from SystemUpdater.backend import DownloadBackend as downb
|
||||
from SystemUpdater.Core.utils import (
|
||||
LockedPreventShutdown,
|
||||
)
|
||||
|
||||
#安装完成之后是否有请求需要重启
|
||||
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"
|
||||
|
||||
|
@ -145,7 +143,7 @@ class UpdateManager():
|
|||
logging.info("Disk Check finished...")
|
||||
try:
|
||||
self.is_upgrading = True
|
||||
self.filelock()
|
||||
LockedPreventShutdown()
|
||||
install_backend = get_backend(self, InstallBackend.ACTION_INSTALL)
|
||||
install_backend.start(force_install,partial_upgrade_list=partial_upgrade_list)
|
||||
except Exception as e:
|
||||
|
@ -158,7 +156,7 @@ class UpdateManager():
|
|||
# return
|
||||
logging.info("Disk Check finished...")
|
||||
self.is_upgrading = True
|
||||
self.filelock()
|
||||
LockedPreventShutdown()
|
||||
install_backend = get_backend(self, InstallBackend.ACTION_INSTALL)
|
||||
install_backend.start_alone(pkgs_install,pkgs_upgrade,pkgs_remove,pkgs_purge)
|
||||
|
||||
|
@ -278,30 +276,6 @@ 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
|
||||
|
|
|
@ -11,6 +11,9 @@ import os
|
|||
from gettext import gettext as _
|
||||
|
||||
import apt_pkg
|
||||
from SystemUpdater.Core.utils import (
|
||||
unLockedEnableShutdown,
|
||||
)
|
||||
|
||||
class InstallBackend():
|
||||
ACTION_UPDATE = 0
|
||||
|
@ -193,6 +196,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,'','')
|
||||
unLockedEnableShutdown()
|
||||
elif action == self.ACTION_UPDATE:
|
||||
self.window_main.is_updating = False
|
||||
if success:
|
||||
|
@ -211,7 +215,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()
|
||||
unLockedEnableShutdown()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -12,33 +12,30 @@ import sys
|
|||
import fcntl
|
||||
|
||||
from SystemUpdater.Core.LogManager import get_logfile as logfile
|
||||
|
||||
from SystemUpdater.Core.utils import (
|
||||
unLockedEnableShutdown,
|
||||
)
|
||||
|
||||
#定义日志的格式
|
||||
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")
|
||||
try:
|
||||
unLockedEnableShutdown()
|
||||
logging.info("SIGTERM received,file unlocked")
|
||||
except:
|
||||
logging.error("File lock release failure")
|
||||
logging.warning("SIGTERM received, will stop")
|
||||
os._exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# LockedPreventShutdown()
|
||||
# Begin parsing of options
|
||||
parser = OptionParser()
|
||||
parser.add_option ("", "--debug", action="store_true", default=False,
|
||||
parser.add_option ("-d", "--debug", action="store_true", default=False,
|
||||
help=_("Show debug messages"))
|
||||
parser.add_option("-r", "--replace",
|
||||
default=False,
|
||||
|
|
Loading…
Reference in New Issue