更策略新服务,增加超时退出

This commit is contained in:
Luoxueyi 2022-09-19 11:28:17 +08:00
parent fd459f16ff
commit 4dad9bd998
4 changed files with 22 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import dbus.service
import traceback
from gettext import gettext as _
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
DBusGMainLoop(set_as_default=True)
from .UpgradeStrategiesDbus import UpgradeStrategiesDbusController,UPDATER_DBUS_INTERFACE,UPDATER_DBUS_PATH,UPDATER_DBUS_SERVICE
@ -17,6 +18,8 @@ from .Core.loop import mainloop
from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig
STRATEGY_IDLE_INTERVAL = 5
STRATEGY_IDLE_TIMEOUT = 5
class UpgradeStrategies():
def __init__(self,options):
try:
@ -26,7 +29,10 @@ class UpgradeStrategies():
#config
self.uuconfigs = UpgradeConfig(datadir = "/var/lib/unattended-upgrades/", name = "unattended-upgrades-policy.conf")
self.sqlite3_server = Sqlite3Server(self)
#策略配置接口的超时退出机制
self.strategy_timestamp = 0
GLib.timeout_add_seconds(STRATEGY_IDLE_INTERVAL,
self._check_strategy_inactivity)
except Exception as e:
logging.error(e)
traceback.print_exc()
@ -80,3 +86,16 @@ class UpgradeStrategies():
timeout=300)
logging.error("Dbus has not withdrawn and retry reboot times:%d...",retry_reboot_times)
time.sleep(1)
def _check_strategy_inactivity(self):
logging.info("Checking for inactivity in Strategies daemon ...")
timestamp = self.strategy_timestamp
if timestamp == 0:
self.strategy_timestamp = time.time()
return True
#超时退出
if self.strategy_timestamp != 0 and time.time() - self.strategy_timestamp > STRATEGY_IDLE_TIMEOUT:
logging.warning("Quitting due to inactivity")
self.dbusController.Quit(None)
return False
return True

View File

@ -6,7 +6,7 @@
<vendor>Kylin System Updater Config Manager</vendor>
<vendor_url>www.kylinos.cn</vendor_url>
<icon_name>kylin-system-updater-UpgradeStrategies</icon_name>
<icon_name>kylin-upgrade-strategies</icon_name>
<action id="com.kylin.UpgradeStrategies.action">
<_description>

View File

@ -22,7 +22,7 @@ backend/data/kylin-system-version.conf /etc/kylin-version/
#configDaemon
backend/kylin-upgrade-strategies /usr/share/kylin-system-updater/
backend/data/com.kylin.UpgradeStrategies.conf /etc/dbus-1/system.d/
backend/data/kylin-upgrade-strategies.service /usr/lib/systemd/system/
backend/data/com.kylin.UpgradeStrategies.service /usr/share/dbus-1/system-services/
backend/data/cn.kylinos.UpgradeStrategies.policy /usr/share/polkit-1/actions/
#uu