remove timming install job in mavis
This commit is contained in:
parent
cc562bef92
commit
b0cd678b0f
|
@ -122,8 +122,8 @@ DISTRO_ID = subprocess.check_output(
|
|||
DEVEL_UNTIL_RELEASE = datetime.timedelta(days=21)
|
||||
|
||||
# progress information is written here
|
||||
PROGRESS_LOG = "/var/run/unattended-upgrades.progress"
|
||||
PID_FILE = "/var/run/unattended-upgrades.pid"
|
||||
PROGRESS_LOG = "/var/run/kylin-unattended-upgrades.progress"
|
||||
PID_FILE = "/var/run/kylin-unattended-upgrades.pid"
|
||||
LOCK_FILE = "/var/run/kylin-unattended-upgrades.lock"
|
||||
NOTIFICATION_PIPE = '/tmp/notification.pipe'
|
||||
# 禁止关机锁文件路径
|
||||
|
@ -140,7 +140,7 @@ def ReadOsRelease(file):
|
|||
lines = f.readlines()
|
||||
for line in lines:
|
||||
ls = line.strip().split('=',1)
|
||||
osreleasedict.update({ls[0]:ls[1]})
|
||||
osreleasedict.update({ls[0]:ls[1].strip('"')})
|
||||
except Exception as e:
|
||||
pass
|
||||
return osreleasedict
|
||||
|
@ -295,10 +295,14 @@ class FILE_LOCK(object):
|
|||
|
||||
class ConfigFileManager:
|
||||
def __init__(self,rootdir):
|
||||
self.rootdir = rootdir
|
||||
self.filenamelist = []
|
||||
if not os.path.exists(rootdir):
|
||||
os.mkdirs(rootdir)
|
||||
self.rootdir = rootdir
|
||||
|
||||
def SetRootDir(self,rootdir):
|
||||
if not os.path.exists(rootdir):
|
||||
os.mkdirs(rootdir)
|
||||
self.rootdir=rootdir
|
||||
|
||||
def AddFileName(self,filename):
|
||||
|
@ -2585,7 +2589,7 @@ def run(options, # type: Options
|
|||
# check if today is a patch day
|
||||
# if not is_update_day():
|
||||
# return UnattendedUpgradesResult(True)
|
||||
logging.info(_("Starting unattended upgrades script"))
|
||||
logging.info(_("Starting unattended upgrades script at"))
|
||||
# check if u-u should be stopped already
|
||||
if should_stop():
|
||||
return UnattendedUpgradesResult(False)
|
||||
|
@ -2804,9 +2808,10 @@ def run(options, # type: Options
|
|||
logging.info("all pkgs downloaded")
|
||||
insmod = ReadValueFromFile("/var/lib/unattended-upgrades/unattended-upgrades-policy.conf","autoUpgradePolicy","installmode")
|
||||
if insmod == 'bshutdown':
|
||||
configfilemanager.AddFileName("OTA_PKGS_TO_INSTALL")
|
||||
subprocess.Popen('dbus-send --system --type=signal / com.kylin.update.notification.DownloadFinish', shell=True)
|
||||
kylin_system_updater.SetConfigValue('InstallMode','auto_install','True')
|
||||
if len(pkgs_to_upgrade) > 0:
|
||||
configfilemanager.AddFileName("OTA_PKGS_TO_INSTALL")
|
||||
subprocess.Popen('dbus-send --system --type=signal / com.kylin.update.notification.DownloadFinish', shell=True)
|
||||
kylin_system_updater.SetConfigValue('InstallMode','auto_install','True')
|
||||
elif insmod == 'timing':
|
||||
pass
|
||||
else:
|
||||
|
@ -3213,6 +3218,7 @@ if __name__ == "__main__":
|
|||
_setup_logging(options,logfile)
|
||||
#get os release info
|
||||
os_release_info = ReadOsRelease('/etc/os-release')
|
||||
print(os_release_info)
|
||||
config_manager = ConfigFileManager(CONFIG_FILE_ROOT_PATH)
|
||||
kylin_system_updater = KylinSystemUpdater()
|
||||
allow_autoupdate = kylin_system_updater.GetDatabaseInfo("display","autoupdate_allow")
|
||||
|
|
|
@ -62,6 +62,13 @@ except Exception:
|
|||
logging.exception("importing of apt_pkg failed, exiting")
|
||||
sys.exit(0)
|
||||
|
||||
# progress information is written here
|
||||
PROGRESS_LOG = "/var/run/kylin-unattended-upgrades.progress"
|
||||
PID_FILE = "/var/run/kylin-unattended-upgrades.pid"
|
||||
LOCK_FILE = "/var/run/kylin-unattended-upgrades.lock"
|
||||
PKGS_TO_INSTALL_FLAG_FILE="/var/lib/unattended-upgrades/OTA_PKGS_TO_INSTALL"
|
||||
|
||||
|
||||
## analytic unattended-upgrades-policy.conf start
|
||||
POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY = "autoUpgradePolicy"
|
||||
AUTO_UPGRADE_POLICY_OPTION_PREDOWNLOAD = "preDownload"
|
||||
|
@ -110,7 +117,7 @@ def ReadOsRelease(file):
|
|||
lines = f.readlines()
|
||||
for line in lines:
|
||||
ls = line.strip().split('=',1)
|
||||
osreleasedict.update({ls[0]:ls[1]})
|
||||
osreleasedict.update({ls[0]:ls[1].strip('"')})
|
||||
except Exception as e:
|
||||
pass
|
||||
return osreleasedict
|
||||
|
@ -175,21 +182,25 @@ def log_progress():
|
|||
# type: () -> None
|
||||
""" helper to log the install progress (if any) """
|
||||
# wait a some seconds and try again
|
||||
'''
|
||||
msg = _("Unattended-upgrade in progress during shutdown, "
|
||||
"please don't turn off the computer")
|
||||
'''
|
||||
# progress info
|
||||
progress = "/var/run/unattended-upgrades.progress"
|
||||
if os.path.exists(progress):
|
||||
pgss = open(progress).read()
|
||||
msg += "\n" + pgss
|
||||
# log it
|
||||
log_msg(msg)
|
||||
subprocess.call(["/bin/plymouth","system-update","--progress=%s"%pgss])
|
||||
|
||||
progress_file = "/var/run/kylin-unattended-upgrades.progress"
|
||||
if os.path.exists(progress_file):
|
||||
progress_text = open(progress_file).read()
|
||||
logging.debug("progress text content %s"%progress_text)
|
||||
if len(progress_text):
|
||||
progress = int(float(progress_text))
|
||||
subprocess.call(["/bin/plymouth","system-update","--progress=%d"%progress])
|
||||
msg = "upgrage progress %s"%progress_text
|
||||
log_msg(msg)
|
||||
|
||||
|
||||
def signal_stop_unattended_upgrade():
|
||||
""" send SIGTERM to running unattended-upgrade if there is any """
|
||||
pidfile = "/var/run/unattended-upgrades.pid"
|
||||
pidfile = PID_FILE#"/var/run/unattended-upgrades.pid"
|
||||
if os.path.exists(pidfile):
|
||||
pid = int(open(pidfile).read())
|
||||
logging.debug("found running unattended-upgrades pid %s" % pid)
|
||||
|
@ -201,15 +212,21 @@ def signal_stop_unattended_upgrade():
|
|||
|
||||
|
||||
def exit_log_result(success):
|
||||
if os.path.exists(PKGS_TO_INSTALL_FLAG_FILE):
|
||||
os.remove(PKGS_TO_INSTALL_FLAG_FILE)
|
||||
subprocess.call(["/bin/plymouth","system-update","--progress=100"])
|
||||
time.sleep(3)
|
||||
subprocess.run(["/bin/plymouth","quit","--retain-splash"])
|
||||
if success:
|
||||
log_msg(_("All upgrades installed"), logging.INFO)
|
||||
logging.debug("All upgrades installed")
|
||||
#log_msg(_("All upgrades installed"), logging.INFO)
|
||||
os._exit(0)
|
||||
sys.exit(0)
|
||||
#sys.exit(0)
|
||||
else:
|
||||
log_msg(_("Unattended-upgrades stopped. There may be upgrades"
|
||||
" left to be installed in the next run."), logging.INFO)
|
||||
os._exit(1)
|
||||
sys.exit(1)
|
||||
#sys.exit(1)
|
||||
|
||||
# 检查时间安全性 -- minute > 59; hour > 23;
|
||||
def check_time_safety(inTime):
|
||||
|
@ -306,6 +323,7 @@ class UnattendedUpgradesShutdown():
|
|||
hasattr(GLib, "MainLoop")
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
except NameError:
|
||||
logging.error("DBusGMainLoop error")
|
||||
pass
|
||||
try:
|
||||
self.inhibit_lock = self.get_inhibit_shutdown_lock()
|
||||
|
@ -383,6 +401,7 @@ class UnattendedUpgradesShutdown():
|
|||
GLib.timeout_add(0, lambda: self.iter() and False)
|
||||
except NameError:
|
||||
pass
|
||||
return True
|
||||
|
||||
def run_polling(self, signal_handler):
|
||||
logging.warning(
|
||||
|
@ -467,7 +486,8 @@ class UnattendedUpgradesShutdown():
|
|||
try:
|
||||
hasattr(GLib, "MainLoop")
|
||||
except NameError:
|
||||
self.run_polling(signal_handler)
|
||||
logging.error("MainLoop Not Found")
|
||||
#self.run_polling(signal_handler)
|
||||
return
|
||||
|
||||
for sig in (signal.SIGTERM, signal.SIGHUP):
|
||||
|
@ -552,7 +572,7 @@ class UnattendedUpgradesShutdown():
|
|||
if self.install_mode == InstallMode.BEFORE_SHUTDOWN_INSTALL.value:
|
||||
if self.update_interface.GetConfigValue('InstallMode','shutdown_install'):
|
||||
#show plymouth splash if bsshutdown is set
|
||||
if os.path.exists('/var/lib/unattended-upgrades/OTA_PKGS_TO_INSTALL'):
|
||||
if os.path.exists(PKGS_TO_INSTALL_FLAG_FILE):
|
||||
do_plymouth_splash()
|
||||
self.start_iterations()
|
||||
else:
|
||||
|
@ -585,9 +605,12 @@ 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'])
|
||||
self.install_job = self.scheduler.add_job(self.timing_install, 'cron', hour=self.install_time_r['h'], minute=self.install_time_r['m'])
|
||||
if os_release_info['PROJECT_CODENAME'] == 'V10SP1-edu' and os_release_info['SUB_PROJECT_CODENAME']=='mavis':
|
||||
logging.info("mavis project")
|
||||
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()
|
||||
|
||||
|
@ -608,13 +631,14 @@ class UnattendedUpgradesShutdown():
|
|||
self.apt_pkg_reinit_done = False
|
||||
|
||||
if self.on_shutdown_mode is None:
|
||||
self.on_shutdown_mode = (
|
||||
not self.options.stop_only
|
||||
and not self.stop_signal_received.is_set()
|
||||
and self.apt_pkg_reinit_done
|
||||
self.on_shutdown_mode = True
|
||||
#(
|
||||
#not self.options.stop_only
|
||||
#and not self.stop_signal_received.is_set()
|
||||
#and self.apt_pkg_reinit_done
|
||||
# and apt_pkg.config.find_b(
|
||||
# "Unattended-Upgrade::InstallOnShutdown", False)
|
||||
)
|
||||
#)
|
||||
if self.on_shutdown_mode:
|
||||
env = copy.copy(os.environ)
|
||||
#env["UNATTENDED_UPGRADES_FORCE_INSTALL_ON_SHUTDOWN"] = "1"
|
||||
|
@ -646,7 +670,7 @@ class UnattendedUpgradesShutdown():
|
|||
self.max_delay / 60)
|
||||
os._exit(1)
|
||||
#sys.exit(1)
|
||||
|
||||
|
||||
if not self.stop_signal_received.is_set():
|
||||
if self.try_iter_on_shutdown():
|
||||
return True
|
||||
|
@ -657,7 +681,7 @@ class UnattendedUpgradesShutdown():
|
|||
# exit here if there is no lock
|
||||
if res > 0:
|
||||
logging.debug("lock not taken")
|
||||
os._exit(0)
|
||||
#os._exit(0)
|
||||
if self.lock_was_taken:
|
||||
exit_log_result(self.signal_sent)
|
||||
else:
|
||||
|
@ -671,7 +695,6 @@ class UnattendedUpgradesShutdown():
|
|||
|
||||
|
||||
def main():
|
||||
|
||||
# setup gettext
|
||||
localesApp = "unattended-upgrades"
|
||||
localesDir = "/usr/share/locale"
|
||||
|
@ -680,11 +703,11 @@ def main():
|
|||
|
||||
# use a normal logfile instead of syslog too as on shutdown its too
|
||||
# easy to get syslog killed
|
||||
logdir = "/var/log/unattended-upgrades/"
|
||||
logdir = "/var/log/kylin-unattended-upgrades/"
|
||||
try:
|
||||
apt_pkg.init_config()
|
||||
logdir = apt_pkg.config.find_dir(
|
||||
"Unattended-Upgrade::LogDir", logdir)
|
||||
# logdir = apt_pkg.config.find_dir(
|
||||
# "Unattended-Upgrade::LogDir", logdir)
|
||||
except apt_pkg.Error as error:
|
||||
logging.error(_("Apt returned an error when loading configuration, "
|
||||
"using default values"))
|
||||
|
@ -699,7 +722,7 @@ def main():
|
|||
parser.add_option("", "--delay", default=25, type="int",
|
||||
help="delay in minutes to wait for unattended-upgrades")
|
||||
parser.add_option("", "--lock-file",
|
||||
default="/var/run/unattended-upgrades.lock",
|
||||
default="/var/run/kylin-unattended-upgrades.lock",
|
||||
help="lock file location")
|
||||
parser.add_option("", "--stop-only",
|
||||
action="store_true", dest="stop_only", default=False,
|
||||
|
@ -724,9 +747,11 @@ def main():
|
|||
level=level,
|
||||
format="%(asctime)s %(levelname)s - %(message)s")
|
||||
clean_flag_files(flag_file_list)
|
||||
init()
|
||||
# init()
|
||||
|
||||
UnattendedUpgradesShutdown(options).run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
os_release_info = ReadOsRelease('/etc/os-release')
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue