mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Call app remove script if installation fails
This commit is contained in:
parent
5c12ad36bf
commit
8114de167b
2 changed files with 39 additions and 28 deletions
|
@ -27,6 +27,7 @@
|
||||||
"app_upgrade_failed" : "Unable to upgrade {app:s}",
|
"app_upgrade_failed" : "Unable to upgrade {app:s}",
|
||||||
"app_id_invalid" : "Invalid app id",
|
"app_id_invalid" : "Invalid app id",
|
||||||
"app_already_installed" : "{app:s} is already installed",
|
"app_already_installed" : "{app:s} is already installed",
|
||||||
|
"app_not_properly_removed" : "{app:s} has not been properly removed",
|
||||||
"app_removed" : "{app:s} successfully removed",
|
"app_removed" : "{app:s} successfully removed",
|
||||||
"app_location_already_used" : "An app is already installed on this location",
|
"app_location_already_used" : "An app is already installed on this location",
|
||||||
"app_location_install_failed" : "Unable to install the app on this location",
|
"app_location_install_failed" : "Unable to install the app on this location",
|
||||||
|
|
|
@ -507,37 +507,47 @@ def app_install(auth, app, label=None, args=None):
|
||||||
# Move scripts and manifest to the right place
|
# Move scripts and manifest to the right place
|
||||||
os.system('cp %s/manifest.json %s' % (app_tmp_folder, app_setting_path))
|
os.system('cp %s/manifest.json %s' % (app_tmp_folder, app_setting_path))
|
||||||
os.system('cp -R %s/scripts %s' % (app_tmp_folder, app_setting_path))
|
os.system('cp -R %s/scripts %s' % (app_tmp_folder, app_setting_path))
|
||||||
|
|
||||||
|
# Execute the app install script
|
||||||
|
install_retcode = 1
|
||||||
try:
|
try:
|
||||||
if hook_exec(app_tmp_folder + '/scripts/install', args_list) == 0:
|
install_retcode = hook_exec(
|
||||||
# Store app status
|
os.path.join(app_tmp_folder, 'scripts/install'), args_list)
|
||||||
with open(app_setting_path + '/status.json', 'w+') as f:
|
except (KeyboardInterrupt, EOFError):
|
||||||
json.dump(status, f)
|
install_retcode = -1
|
||||||
|
|
||||||
# Clean and set permissions
|
|
||||||
shutil.rmtree(app_tmp_folder)
|
|
||||||
os.system('chmod -R 400 %s' % app_setting_path)
|
|
||||||
os.system('chown -R root: %s' % app_setting_path)
|
|
||||||
os.system('chown -R admin: %s/scripts' % app_setting_path)
|
|
||||||
app_ssowatconf(auth)
|
|
||||||
logger.success(m18n.n('installation_complete'))
|
|
||||||
else:
|
|
||||||
raise MoulinetteError(errno.EIO, m18n.n('installation_failed'))
|
|
||||||
except:
|
except:
|
||||||
# Execute remove script and clean folders
|
logger.exception(m18n.n('unexpected_error'))
|
||||||
hook_remove(app_id)
|
finally:
|
||||||
shutil.rmtree(app_setting_path)
|
if install_retcode != 0:
|
||||||
shutil.rmtree(app_tmp_folder)
|
# Execute remove script
|
||||||
|
remove_retcode = hook_exec(
|
||||||
|
os.path.join(app_tmp_folder, 'scripts/remove'), [app_id])
|
||||||
|
if remove_retcode != 0:
|
||||||
|
logger.warning(m18n.n('app_not_properly_removed', app=app_id))
|
||||||
|
|
||||||
# Reraise proper exception
|
# Clean tmp folders
|
||||||
try:
|
hook_remove(app_id)
|
||||||
raise
|
shutil.rmtree(app_setting_path)
|
||||||
except MoulinetteError:
|
shutil.rmtree(app_tmp_folder)
|
||||||
raise
|
|
||||||
except (KeyboardInterrupt, EOFError):
|
if install_retcode == -1:
|
||||||
raise MoulinetteError(errno.EINTR, m18n.g('operation_interrupted'))
|
raise MoulinetteError(errno.EINTR,
|
||||||
except Exception as e:
|
m18n.g('operation_interrupted'))
|
||||||
logger.debug('app installation failed', exc_info=1)
|
raise MoulinetteError(errno.EIO, m18n.n('installation_failed'))
|
||||||
raise MoulinetteError(errno.EIO, m18n.n('unexpected_error'))
|
|
||||||
|
# Store app status
|
||||||
|
with open(app_setting_path + '/status.json', 'w+') as f:
|
||||||
|
json.dump(status, f)
|
||||||
|
|
||||||
|
# Clean and set permissions
|
||||||
|
shutil.rmtree(app_tmp_folder)
|
||||||
|
os.system('chmod -R 400 %s' % app_setting_path)
|
||||||
|
os.system('chown -R root: %s' % app_setting_path)
|
||||||
|
os.system('chown -R admin: %s/scripts' % app_setting_path)
|
||||||
|
|
||||||
|
app_ssowatconf(auth)
|
||||||
|
|
||||||
|
logger.success(m18n.n('installation_complete'))
|
||||||
|
|
||||||
|
|
||||||
def app_remove(auth, app):
|
def app_remove(auth, app):
|
||||||
|
|
Loading…
Add table
Reference in a new issue