[enh] Catch each command error and be more verbose in upgrade_v24

This commit is contained in:
Jérôme Lebleu 2016-05-16 13:04:56 +02:00
parent 38a96ca43c
commit 3ffaf913c5
2 changed files with 51 additions and 14 deletions

View file

@ -35,6 +35,8 @@ import logging
import apt import apt
import apt.progress import apt.progress
import platform import platform
import shutil
import subprocess
from moulinette.core import MoulinetteError from moulinette.core import MoulinetteError
from moulinette.utils.log import getActionLogger from moulinette.utils.log import getActionLogger
@ -481,19 +483,33 @@ def tools_upgrade_v24(auth):
""" """
YunoHost upgrade to new Yunohost version (on jessie) YunoHost upgrade to new Yunohost version (on jessie)
""" """
# Retrieve interface
is_api = True if msettings.get('interface') == 'api' else False
# Get Debian major version # Get Debian major version
debian_major_version = platform.linux_distribution()[1].split('.')[0] debian_major_version = platform.linux_distribution()[1].split('.')[0]
if debian_major_version is not '8': if debian_major_version != '8':
msignals.display(m18n.n('upgrade_24_not_jessie'), 'error') msignals.display(m18n.n('upgrade_24_not_jessie'), 'error')
return return
# Prepare environment and commands
env = os.environ.copy()
env['DEBIAN_FRONTEND'] = 'noninteractive'
env['DEBIAN_PRIORITY'] = 'critical'
apt_cmd = ['apt-get', '-y', '--force-yes', '-qq',
'-o', 'Dpkg::Options::=--force-confdef',
'-o', 'Dpkg::Options::=--force-confold']
_call = lambda cmd: subprocess.call(cmd, env=env)
_apt = lambda cmd: _call(apt_cmd + cmd)
# Upgrade with current sources # Upgrade with current sources
os.system('apt-get update') if _apt(['update',]) != 0:
os.system('yes "q" | DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get -y --force-yes -qq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade') raise MoulinetteError(errno.EIO,
m18n.n('upgrade_24_update_failed'))
if _apt(['upgrade',]) != 0:
msignals.display(m18n.n('upgrade_24_system_failed'), 'error')
# Attempt to repair the system
if _apt(['-f', 'install']) != 0 or _apt(['upgrade',]) != 0:
raise MoulinetteError(errno.EIO,
m18n.n('packages_upgrade_failed'))
msignals.display(m18n.n('upgrade_24_system_done'), 'success')
# Remove old repo in sources.list file # Remove old repo in sources.list file
with open('/etc/apt/sources.list', "r") as sources: with open('/etc/apt/sources.list', "r") as sources:
@ -508,18 +524,32 @@ def tools_upgrade_v24(auth):
sources.write('deb http://repo.yunohost.org/debian/ jessie stable') sources.write('deb http://repo.yunohost.org/debian/ jessie stable')
# Upgrade with new sources # Upgrade with new sources
os.system('apt-get update') if _apt(['update',]) != 0:
os.system('yes "q" | DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get install -y --force-yes -qq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" yunohost') raise MoulinetteError(errno.EIO,
os.system('yes "q" | DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get -y --force-yes -qq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade') m18n.n('upgrade_24_update_failed'))
os.system('yes "q" | DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get remove -y --force-yes amavisd-new') if _apt(['install', 'yunohost',]) != 0:
os.system('yes "q" | DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get -y --force-yes autoremove') raise MoulinetteError(errno.EIO,
os.system('yunohost service regen-conf -f') m18n.n('upgrade_24_yunohost_install_failed'))
msignals.display(m18n.n('upgrade_24_yunohost_installed'))
# Remove unused packages and folders
if _apt(['autoremove',]) != 0:
msignals.display(m18n.n('upgrade_24_autoremove_failed'), 'error')
# Remove at least amavis and spamassassin
_apt(['remove', 'amavisd-new', 'spamassassin'])
shutil.rmtree('/usr/share/yunohost/miniupnp-src', ignore_errors=True)
# Regenerate configuration
if _call(['yunohost', 'service', 'regen-conf', '-f']) != 0:
msignals.display(m18n.n('upgrade_24_regenconf_failed'))
msignals.display(m18n.n('system_upgraded'), 'success') msignals.display(m18n.n('system_upgraded'), 'success')
# Prepare systemctl # Prepare systemctl
with open('/etc/cron.d/yunohost-regenconf', 'w+') as f: with open('/etc/cron.d/yunohost-regenconf', 'w+') as f:
f.write('* * * * * root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin systemctl start yunohost-api && rm -f /etc/cron.d/yunohost-regenconf\n' ) f.write('* * * * * root PATH=/usr/sbin:/usr/bin:/sbin:/bin '
'systemctl start yunohost-api && '
'rm -f /etc/cron.d/yunohost-regenconf\n')
# Reboot user notice # Reboot user notice
msignals.display(m18n.n('upgrade_24_reboot'), 'warning') msignals.display(m18n.n('upgrade_24_reboot'), 'warning')

View file

@ -198,6 +198,13 @@
"format_datetime_short" : "%m/%d/%Y %I:%M %p", "format_datetime_short" : "%m/%d/%Y %I:%M %p",
"upgrade_24_not_jessie" : "Upgrading to YunoHost v2.4 will only work on Debian Jessie. Please upgrade your system before upgrading YunoHost.", "upgrade_24_not_jessie" : "Upgrading to YunoHost v2.4 will only work on Debian Jessie. Please upgrade your system before upgrading YunoHost.",
"upgrade_24_update_failed" : "An error occurred while updating the packages list, you should maybe check your network connection.",
"upgrade_24_system_failed" : "An error occurred while upgrading your system, we will try to fix broken packages...",
"upgrade_24_system_done" : "Your system has been upgraded, the new YunoHost version can be installed...",
"upgrade_24_yunohost_install_failed" : "An error occurred while installing new yunohost package version. Please see the log and ask for help on the forum or the support chat room.",
"upgrade_24_yunohost_installed" : "The new YunoHost version has been installed! Now removing unused packages and regenerate the configuration...",
"upgrade_24_autoremove_failed" : "An error occurred while removing unused packages, you should check what failed.",
"upgrade_24_regenconf_failed" : "The configuration regeneration for services failed",
"upgrade_24_reboot" : "You must reboot your server for the changes to take effect. Enter the 'reboot' command right now." "upgrade_24_reboot" : "You must reboot your server for the changes to take effect. Enter the 'reboot' command right now."
} }