mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Be more verbose on system update/upgrade and fix it
This commit is contained in:
parent
33de61586b
commit
47ee2ae630
2 changed files with 40 additions and 12 deletions
|
@ -114,8 +114,12 @@
|
||||||
"yunohost_already_installed" : "YunoHost is already installed",
|
"yunohost_already_installed" : "YunoHost is already installed",
|
||||||
"yunohost_ca_creation_failed" : "Unable to create certificate authority",
|
"yunohost_ca_creation_failed" : "Unable to create certificate authority",
|
||||||
"yunohost_configured" : "YunoHost successfully configured",
|
"yunohost_configured" : "YunoHost successfully configured",
|
||||||
|
"updating_apt_cache" : "Updating the lists of available packages...",
|
||||||
"update_cache_failed" : "Unable to update APT cache",
|
"update_cache_failed" : "Unable to update APT cache",
|
||||||
"system_no_upgrade" : "There is no packages to upgrade",
|
"packages_no_upgrade" : "There is no package to upgrade",
|
||||||
|
"packages_upgrade_critical_later" : "Critical packages (%s) will be upgraded later",
|
||||||
|
"upgrading_packages" : "Upgrading packages...",
|
||||||
|
"packages_upgrade_failed" : "Unable to upgrade all packages",
|
||||||
"system_upgraded" : "System successfully upgraded",
|
"system_upgraded" : "System successfully upgraded",
|
||||||
|
|
||||||
"field_invalid" : "Invalid field '%s'",
|
"field_invalid" : "Invalid field '%s'",
|
||||||
|
|
38
tools.py
38
tools.py
|
@ -306,9 +306,12 @@ def tools_update(ignore_apps=False, ignore_packages=False):
|
||||||
packages = []
|
packages = []
|
||||||
if not ignore_packages:
|
if not ignore_packages:
|
||||||
cache = apt.Cache()
|
cache = apt.Cache()
|
||||||
|
|
||||||
# Update APT cache
|
# Update APT cache
|
||||||
|
msignals.display(m18n.n('updating_apt_cache'))
|
||||||
if not cache.update():
|
if not cache.update():
|
||||||
raise MoulinetteError(errno.EPERM, m18n.n('update_cache_failed'))
|
raise MoulinetteError(errno.EPERM, m18n.n('update_cache_failed'))
|
||||||
|
msignals.display(m18n.n('done'))
|
||||||
|
|
||||||
cache.open(None)
|
cache.open(None)
|
||||||
cache.upgrade(True)
|
cache.upgrade(True)
|
||||||
|
@ -350,7 +353,7 @@ def tools_update(ignore_apps=False, ignore_packages=False):
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(apps) == 0 and len(packages) == 0:
|
if len(apps) == 0 and len(packages) == 0:
|
||||||
msignals.display(m18n.n('system_no_upgrade'), 'success')
|
msignals.display(m18n.n('packages_no_upgrade'))
|
||||||
|
|
||||||
return { 'packages': packages, 'apps': apps }
|
return { 'packages': packages, 'apps': apps }
|
||||||
|
|
||||||
|
@ -366,25 +369,45 @@ def tools_upgrade(ignore_apps=False, ignore_packages=False):
|
||||||
"""
|
"""
|
||||||
from yunohost.app import app_upgrade
|
from yunohost.app import app_upgrade
|
||||||
|
|
||||||
|
is_api = True if msettings.get('interface') == 'api' else False
|
||||||
|
|
||||||
if not ignore_packages:
|
if not ignore_packages:
|
||||||
cache = apt.Cache()
|
cache = apt.Cache()
|
||||||
cache.open(None)
|
cache.open(None)
|
||||||
cache.upgrade(True)
|
cache.upgrade(True)
|
||||||
|
|
||||||
# If API call
|
# If API call
|
||||||
if not os.isatty(1):
|
if is_api:
|
||||||
critical_packages = ["moulinette", "moulinette-yunohost", "yunohost-admin", "yunohost-config-nginx", "ssowat", "python"]
|
critical_packages = ("moulinette", "moulinette-yunohost",
|
||||||
|
"yunohost-admin", "yunohost-config-nginx", "ssowat", "python")
|
||||||
|
critical_upgrades = set()
|
||||||
|
|
||||||
for pkg in cache.get_changes():
|
for pkg in cache.get_changes():
|
||||||
if pkg.name in critical_packages:
|
if pkg.name in critical_packages:
|
||||||
|
critical_upgrades.add(pkg.name)
|
||||||
# Temporarily keep package ...
|
# Temporarily keep package ...
|
||||||
pkg.mark_keep()
|
pkg.mark_keep()
|
||||||
# ... and set a hourly cron up to upgrade critical packages
|
# ... and set a hourly cron up to upgrade critical packages
|
||||||
|
if critical_upgrades:
|
||||||
|
msignals.display(m18n.n('packages_upgrade_critical_later')
|
||||||
|
% ', '.join(critical_upgrades))
|
||||||
with open('/etc/cron.d/yunohost-upgrade', 'w+') as f:
|
with open('/etc/cron.d/yunohost-upgrade', 'w+') as f:
|
||||||
f.write('00 * * * * root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin apt-get install '+ ' '.join(critical_packages) + ' -y && rm -f /etc/cron.d/yunohost-upgrade')
|
f.write('00 * * * * root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin apt-get install %s -y && rm -f /etc/cron.d/yunohost-upgrade' % ' '.join(critical_upgrades))
|
||||||
|
|
||||||
|
if cache.get_changes():
|
||||||
|
msignals.display(m18n.n('upgrading_packages'))
|
||||||
try:
|
try:
|
||||||
# Apply APT changes
|
# Apply APT changes
|
||||||
cache.commit(apt.progress.text.AcquireProgress(), apt.progress.base.InstallProgress())
|
# TODO: Logs output for the API
|
||||||
except: pass
|
cache.commit(apt.progress.text.AcquireProgress(),
|
||||||
|
apt.progress.base.InstallProgress())
|
||||||
|
except Exception as e:
|
||||||
|
logging.warning('unable to upgrade packages: %s' % str(e))
|
||||||
|
msignals.display(m18n.n('packages_upgrade_failed'), 'error')
|
||||||
|
else:
|
||||||
|
msignals.display(m18n.n('done'))
|
||||||
|
else:
|
||||||
|
msignals.display(m18n.n('packages_no_upgrade'))
|
||||||
|
|
||||||
if not ignore_apps:
|
if not ignore_apps:
|
||||||
try:
|
try:
|
||||||
|
@ -394,5 +417,6 @@ def tools_upgrade(ignore_apps=False, ignore_packages=False):
|
||||||
msignals.display(m18n.n('system_upgraded'), 'success')
|
msignals.display(m18n.n('system_upgraded'), 'success')
|
||||||
|
|
||||||
# Return API logs if it is an API call
|
# Return API logs if it is an API call
|
||||||
if not os.isatty(1):
|
if msettings.get('interface') == 'api':
|
||||||
|
from yunohost.service import service_log
|
||||||
return { "log": service_log('yunohost-api', number="100").values()[0] }
|
return { "log": service_log('yunohost-api', number="100").values()[0] }
|
||||||
|
|
Loading…
Add table
Reference in a new issue