mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Properly handle the sanity checks right after upgrades (in combination with managing the regular error code...). This is similar to what's done for app_install
This commit is contained in:
parent
08ecace5ec
commit
c530325e29
1 changed files with 66 additions and 41 deletions
|
@ -666,56 +666,81 @@ def app_upgrade(app=[], url=None, file=None):
|
||||||
|
|
||||||
# Execute App upgrade script
|
# Execute App upgrade script
|
||||||
os.system('chown -hR admin: %s' % INSTALL_TMP)
|
os.system('chown -hR admin: %s' % INSTALL_TMP)
|
||||||
if hook_exec(extracted_app_folder + '/scripts/upgrade',
|
|
||||||
args=args_list, env=env_dict)[0] != 0:
|
|
||||||
msg = m18n.n('app_upgrade_failed', app=app_instance_name)
|
|
||||||
operation_logger.error(msg)
|
|
||||||
|
|
||||||
# display this if there are remaining apps
|
|
||||||
if apps[number + 1:]:
|
try:
|
||||||
logger.error(m18n.n('app_upgrade_stopped'))
|
upgrade_retcode = hook_exec(extracted_app_folder + '/scripts/upgrade',
|
||||||
not_upgraded_apps = apps[number:]
|
args=args_list, env=env_dict)[0]
|
||||||
# we don't want to continue upgrading apps here in case that breaks
|
except (KeyboardInterrupt, EOFError):
|
||||||
# everything
|
upgrade_retcode = -1
|
||||||
raise YunohostError('app_not_upgraded',
|
except Exception:
|
||||||
failed_app=app_instance_name,
|
import traceback
|
||||||
apps=', '.join(not_upgraded_apps))
|
logger.exception(m18n.n('unexpected_error', error=u"\n" + traceback.format_exc()))
|
||||||
|
finally:
|
||||||
|
|
||||||
|
# Did the script succeed ?
|
||||||
|
if upgrade_retcode != 0:
|
||||||
|
error_msg = m18n.n('app_upgrade_failed', app=app_instance_name)
|
||||||
|
operation_logger.error(error_msg)
|
||||||
|
|
||||||
|
# Did it broke the system ?
|
||||||
|
try:
|
||||||
|
broke_the_system = False
|
||||||
|
_assert_system_is_sane_for_app(manifest, "post")
|
||||||
|
except Exception as e:
|
||||||
|
broke_the_system = True
|
||||||
|
error_msg = operation_logger.error(str(e))
|
||||||
|
|
||||||
|
# If upgrade failed or broke the system,
|
||||||
|
# raise an error and interrupt all other pending upgrades
|
||||||
|
if upgrade_retcode != 0 or broke_the_system:
|
||||||
|
|
||||||
|
# display this if there are remaining apps
|
||||||
|
if apps[number + 1:]:
|
||||||
|
logger.error(m18n.n('app_upgrade_stopped'))
|
||||||
|
not_upgraded_apps = apps[number:]
|
||||||
|
# we don't want to continue upgrading apps here in case that breaks
|
||||||
|
# everything
|
||||||
|
raise YunohostError('app_not_upgraded',
|
||||||
|
failed_app=app_instance_name,
|
||||||
|
apps=', '.join(not_upgraded_apps))
|
||||||
|
else:
|
||||||
|
raise YunohostError(error_msg, raw_msg=True)
|
||||||
|
|
||||||
|
# Otherwise we're good and keep going !
|
||||||
else:
|
else:
|
||||||
raise YunohostError(msg)
|
now = int(time.time())
|
||||||
else:
|
# TODO: Move install_time away from app_setting
|
||||||
now = int(time.time())
|
app_setting(app_instance_name, 'update_time', now)
|
||||||
# TODO: Move install_time away from app_setting
|
status['upgraded_at'] = now
|
||||||
app_setting(app_instance_name, 'update_time', now)
|
|
||||||
status['upgraded_at'] = now
|
|
||||||
|
|
||||||
# Clean hooks and add new ones
|
# Clean hooks and add new ones
|
||||||
hook_remove(app_instance_name)
|
hook_remove(app_instance_name)
|
||||||
if 'hooks' in os.listdir(extracted_app_folder):
|
if 'hooks' in os.listdir(extracted_app_folder):
|
||||||
for hook in os.listdir(extracted_app_folder + '/hooks'):
|
for hook in os.listdir(extracted_app_folder + '/hooks'):
|
||||||
hook_add(app_instance_name, extracted_app_folder + '/hooks/' + hook)
|
hook_add(app_instance_name, extracted_app_folder + '/hooks/' + hook)
|
||||||
|
|
||||||
# Store app status
|
# Store app status
|
||||||
with open(app_setting_path + '/status.json', 'w+') as f:
|
with open(app_setting_path + '/status.json', 'w+') as f:
|
||||||
json.dump(status, f)
|
json.dump(status, f)
|
||||||
|
|
||||||
# Replace scripts and manifest and conf (if exists)
|
# Replace scripts and manifest and conf (if exists)
|
||||||
os.system('rm -rf "%s/scripts" "%s/manifest.toml %s/manifest.json %s/conf"' % (app_setting_path, app_setting_path, app_setting_path, app_setting_path))
|
os.system('rm -rf "%s/scripts" "%s/manifest.toml %s/manifest.json %s/conf"' % (app_setting_path, app_setting_path, app_setting_path, app_setting_path))
|
||||||
|
|
||||||
if os.path.exists(os.path.join(extracted_app_folder, "manifest.json")):
|
if os.path.exists(os.path.join(extracted_app_folder, "manifest.json")):
|
||||||
os.system('mv "%s/manifest.json" "%s/scripts" %s' % (extracted_app_folder, extracted_app_folder, app_setting_path))
|
os.system('mv "%s/manifest.json" "%s/scripts" %s' % (extracted_app_folder, extracted_app_folder, app_setting_path))
|
||||||
if os.path.exists(os.path.join(extracted_app_folder, "manifest.toml")):
|
if os.path.exists(os.path.join(extracted_app_folder, "manifest.toml")):
|
||||||
os.system('mv "%s/manifest.toml" "%s/scripts" %s' % (extracted_app_folder, extracted_app_folder, app_setting_path))
|
os.system('mv "%s/manifest.toml" "%s/scripts" %s' % (extracted_app_folder, extracted_app_folder, app_setting_path))
|
||||||
|
|
||||||
for file_to_copy in ["actions.json", "actions.toml", "config_panel.json", "config_panel.toml", "conf"]:
|
for file_to_copy in ["actions.json", "actions.toml", "config_panel.json", "config_panel.toml", "conf"]:
|
||||||
if os.path.exists(os.path.join(extracted_app_folder, file_to_copy)):
|
if os.path.exists(os.path.join(extracted_app_folder, file_to_copy)):
|
||||||
os.system('cp -R %s/%s %s' % (extracted_app_folder, file_to_copy, app_setting_path))
|
os.system('cp -R %s/%s %s' % (extracted_app_folder, file_to_copy, app_setting_path))
|
||||||
|
|
||||||
# So much win
|
# So much win
|
||||||
logger.success(m18n.n('app_upgraded', app=app_instance_name))
|
logger.success(m18n.n('app_upgraded', app=app_instance_name))
|
||||||
|
|
||||||
_assert_system_is_sane_for_app(manifest, "post")
|
hook_callback('post_app_upgrade', args=args_list, env=env_dict)
|
||||||
hook_callback('post_app_upgrade', args=args_list, env=env_dict)
|
operation_logger.success()
|
||||||
operation_logger.success()
|
|
||||||
|
|
||||||
permission_sync_to_user()
|
permission_sync_to_user()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue