mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #687 from YunoHost/crash_debugger
Dump ynh log if an app script fails
This commit is contained in:
commit
6cdffe77a7
2 changed files with 41 additions and 2 deletions
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# It prints a warning to inform that the script was failed, and execute the ynh_clean_setup function if used in the app script
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_exit_properly () {
|
||||
local exit_code=$?
|
||||
if [ "$exit_code" -eq 0 ]; then
|
||||
|
@ -26,8 +25,46 @@ ynh_exit_properly () {
|
|||
trap '' EXIT # Ignore new exit signals
|
||||
set +eu # Do not exit anymore if a command fail or if a variable is empty
|
||||
|
||||
# Small tempo to avoid the next message being mixed up with other DEBUG messages
|
||||
sleep 0.5
|
||||
|
||||
ynh_print_err --message="!!\n $app's script has encountered an error. Its execution was cancelled.\n!!"
|
||||
|
||||
# If the script is executed from the CLI, dump the end of the log that precedes the crash.
|
||||
if [ "$YNH_INTERFACE" == "cli" ]
|
||||
then
|
||||
# Unset xtrace to not spoil the log
|
||||
set +x
|
||||
|
||||
local ynh_log="/var/log/yunohost/yunohost-cli.log"
|
||||
|
||||
# Wait for the log to be fill with the data until the crash.
|
||||
local timeout=0
|
||||
while ! tail --lines=20 "$ynh_log" | grep --quiet "+ ynh_exit_properly"
|
||||
do
|
||||
((timeout++))
|
||||
if [ $timeout -eq 500 ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e "\e[34m\e[1mPlease find here an extract of the log before the crash:\e[0m" >&2
|
||||
# Tail the last 30 lines of log of YunoHost
|
||||
# But remove all lines after "ynh_exit_properly"
|
||||
# Remove the timestamp at the beginning of the line
|
||||
# Remove "yunohost.hook..."
|
||||
# Add DEBUG and color it at the beginning of each log line.
|
||||
echo -e "$(tail --lines=30 "$ynh_log" \
|
||||
| sed '1,/+ ynh_exit_properly/!d' \
|
||||
| sed 's/^[[:digit:]: ,-]*//g' \
|
||||
| sed 's/ *yunohost.hook.*\]/ -/g' \
|
||||
| sed 's/^WARNING /&/g' \
|
||||
| sed 's/^DEBUG /& /g' \
|
||||
| sed 's/^INFO /& /g' \
|
||||
| sed 's/^/\\e[34m\\e[1m[DEBUG]\\e[0m: /g')" >&2
|
||||
set -x
|
||||
fi
|
||||
|
||||
if type -t ynh_clean_setup > /dev/null; then # Check if the function exist in the app script.
|
||||
ynh_clean_setup # Call the function to do specific cleaning for the app.
|
||||
fi
|
||||
|
|
|
@ -28,7 +28,7 @@ import re
|
|||
import tempfile
|
||||
from glob import iglob
|
||||
|
||||
from moulinette import m18n
|
||||
from moulinette import m18n, msettings
|
||||
from yunohost.utils.error import YunohostError
|
||||
from moulinette.utils import log
|
||||
from moulinette.utils.filesystem import read_json
|
||||
|
@ -337,6 +337,8 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
|||
env = {}
|
||||
env['YNH_CWD'] = chdir
|
||||
|
||||
env['YNH_INTERFACE'] = msettings.get('interface')
|
||||
|
||||
stdinfo = os.path.join(tempfile.mkdtemp(), "stdinfo")
|
||||
env['YNH_STDINFO'] = stdinfo
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue