diff --git a/data/helpers.d/print b/data/helpers.d/print index b13186d62..d35c3e929 100644 --- a/data/helpers.d/print +++ b/data/helpers.d/print @@ -5,6 +5,14 @@ ynh_die() { exit "${2:-1}" } +# Display a message in the 'INFO' logging category +# +# usage: ynh_info "Some message" +ynh_info() +{ + echo "$1" >>"$YNH_STDINFO" +} + # Ignore the yunohost-cli log to prevent errors with conditionals commands # # [internal] diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 2e00a7a5a..1fed09425 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -512,7 +512,8 @@ def app_change_url(operation_logger, auth, app, domain, path): os.system('chmod +x %s' % os.path.join(os.path.join(APP_TMP_FOLDER, "scripts"))) os.system('chmod +x %s' % os.path.join(os.path.join(APP_TMP_FOLDER, "scripts", "change_url"))) - if hook_exec(os.path.join(APP_TMP_FOLDER, 'scripts/change_url'), args=args_list, env=env_dict, user="root") != 0: + if hook_exec(os.path.join(APP_TMP_FOLDER, 'scripts/change_url'), + args=args_list, env=env_dict, user="root") != 0: msg = "Failed to change '%s' url." % app logger.error(msg) operation_logger.error(msg) @@ -638,7 +639,8 @@ def app_upgrade(auth, app=[], url=None, file=None): # Execute App upgrade script os.system('chown -hR admin: %s' % INSTALL_TMP) - if hook_exec(extracted_app_folder + '/scripts/upgrade', args=args_list, env=env_dict, user="root") != 0: + if hook_exec(extracted_app_folder + '/scripts/upgrade', + args=args_list, env=env_dict, user="root") != 0: msg = m18n.n('app_upgrade_failed', app=app_instance_name) logger.error(msg) operation_logger.error(msg) @@ -909,7 +911,8 @@ def app_remove(operation_logger, auth, app): operation_logger.extra.update({'env': env_dict}) operation_logger.flush() - if hook_exec('/tmp/yunohost_remove/scripts/remove', args=args_list, env=env_dict, user="root") == 0: + if hook_exec('/tmp/yunohost_remove/scripts/remove', args=args_list, + env=env_dict, user="root") == 0: logger.success(m18n.n('app_removed', app=app)) hook_callback('post_app_remove', args=args_list, env=env_dict) diff --git a/src/yunohost/hook.py b/src/yunohost/hook.py index 2fb179f83..87844ce17 100644 --- a/src/yunohost/hook.py +++ b/src/yunohost/hook.py @@ -26,6 +26,7 @@ import os import re import errno +import tempfile from glob import iglob from moulinette import m18n @@ -337,6 +338,9 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False, env = {} env['YNH_CWD'] = chdir + stdinfo = os.path.join(tempfile.mkdtemp(), "stdinfo") + env['YNH_STDINFO'] = stdinfo + # Construct command to execute if user == "root": command = ['sh', '-c'] @@ -365,9 +369,16 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False, stdout_callback if stdout_callback else lambda l: logger.debug(l.rstrip()), stderr_callback if stderr_callback else lambda l: logger.warning(l.rstrip()), ) + + if stdinfo: + callbacks = ( callbacks[0], callbacks[1], + lambda l: logger.info(l.rstrip())) + logger.debug("About to run the command '%s'" % command) + returncode = call_async_output( - command, callbacks, shell=False, cwd=chdir + command, callbacks, shell=False, cwd=chdir, + stdinfo=stdinfo ) # Check and return process' return code