From b85cfb8c9e0250ea5a925b7293b7330b321c7a9e Mon Sep 17 00:00:00 2001 From: kay0u Date: Mon, 18 Feb 2019 11:47:25 +0100 Subject: [PATCH] Fix ynh_systemd_action --- scripts/_common.sh | 13 +++++++++---- scripts/install | 3 ++- scripts/restore | 3 ++- scripts/upgrade | 3 ++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 90b5f44..2bfa0f4 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,6 +7,9 @@ # | arg: -a, --action= - Action to perform with systemctl. Default: start # | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot. # If not defined it don't wait until the service is completely started. +# WARNING: When using --line_match, you should always add `ynh_clean_check_starting` into your +# `ynh_clean_setup` at the beginning of the script. Otherwise, tail will not stop in case of failure +# of the script. The script will then hang forever. # | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log # | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds. # | arg: -e, --length= - Length of the error log : Default : 20 @@ -37,17 +40,19 @@ ynh_systemd_action() { if [ "$log_path" == "systemd" ] ; then # Read the systemd journal journalctl --unit=$service_name --follow --since=-0 --quiet > "$templog" & + # Get the PID of the journalctl command + local pid_tail=$! else # Read the specified log file tail -F -n0 "$log_path" > "$templog" & + # Get the PID of the tail command + local pid_tail=$! fi - # Get the PID of the tail command - local pid_tail=$! fi echo "${action^} the service $service_name" >&2 systemctl $action $service_name \ - || ( journalctl --lines=$length -u $service_name --no-pager >&2 \ + || ( journalctl --no-pager --lines=$length -u $service_name >&2 \ ; test -e "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \ ; false ) @@ -70,7 +75,7 @@ ynh_systemd_action() { then echo "The service $service_name didn't fully started before the timeout." >&2 echo "Please find here an extract of the end of the log of the service $service_name:" - journalctl --lines=$length -u $service_name --no-pager >&2 + journalctl --no-pager --lines=$length -u $service_name >&2 test -e "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 fi diff --git a/scripts/install b/scripts/install index 2b3f820..6cfdcbe 100644 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,8 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. + ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script diff --git a/scripts/restore b/scripts/restore index b3a0fb7..9a53bfc 100644 --- a/scripts/restore +++ b/scripts/restore @@ -14,7 +14,8 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. + ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script diff --git a/scripts/upgrade b/scripts/upgrade index 7cde37c..b98017a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,7 +14,8 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. + ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script