From e9fdad3413b01e848fd3920616b1c1385b1e3c2a Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 13 May 2021 22:59:00 +0200 Subject: [PATCH] remove others_var --- scripts/install | 2 +- scripts/upgrade | 4 +-- scripts/ynh_supervisor | 69 ++++++++++++++---------------------------- 3 files changed, 26 insertions(+), 49 deletions(-) diff --git a/scripts/install b/scripts/install index 5c87cd7c..2b7c48f0 100644 --- a/scripts/install +++ b/scripts/install @@ -149,7 +149,7 @@ chown $app:$app "$final_path/.env" ynh_script_progression --message="Configuring a supervisor service..." # Create a dedicated supervisor config -ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf --others_var="phpversion" +ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf #================================================= # DEPLOY diff --git a/scripts/upgrade b/scripts/upgrade index ff8f38e5..d1972c52 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -96,7 +96,7 @@ if dpkg --compare-versions "0.10.9~ynh2" gt "$(ynh_read_manifest --manifest="/et ynh_script_progression --message="Configuring a supervisor service..." phpversion=$YNH_PHP_VERSION - ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf --others_var="phpversion" + ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf ynh_script_progression --message="Starting a supervisor service..." ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="systemd" --line_match="success: ${app}-horizon" @@ -235,7 +235,7 @@ ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" ynh_script_progression --message="Upgrading supervisor configuration..." # Create a dedicated supervisor config -ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf --others_var="phpversion" +ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf #================================================= # GENERIC FINALIZATION diff --git a/scripts/ynh_supervisor b/scripts/ynh_supervisor index 340c13e9..be6d47b7 100644 --- a/scripts/ynh_supervisor +++ b/scripts/ynh_supervisor @@ -2,27 +2,20 @@ # Create a dedicated supervisor config # -# usage: ynh_add_supervisor_config [--service=service] [--template=template] [--others_var="list of others variables to replace"] -# | arg: -s, --service= - Service name (optionnal, $app by default) -# | arg: -t, --template= - Name of template file (optionnal, this is 'supervisor' by default, meaning ./conf/supervisor.service will be used as template) -# | arg: -v, --others_var= - List of others variables to replace separated by a space. For example: 'var_1 var_2 ...' +# usage: ynh_add_supervisor_config [--service=service] [--template=template] +# | arg: -s, --service= - Service name (optionnal, `$app` by default) +# | arg: -t, --template= - Name of template file (optionnal, this is 'supervisor' by default, meaning ./conf/supervisor.service will be used as template) # -# This will use the template ../conf/.service -# to generate a supervisor config, by replacing the following keywords -# with global variables that should be defined before calling -# this helper : +# This will use the template `../conf/.service`. # -# __APP__ by $app -# __FINALPATH__ by $final_path -# -# And dynamic variables (from the last example) : -# __VAR_1__ by $var_1 -# __VAR_2__ by $var_2 +# See the documentation of `ynh_add_config` for a description of the template +# format and how placeholders are replaced with actual variables. # +# Requires YunoHost version 2.7.11 or higher. ynh_add_supervisor_config () { # Declare an array to define the options of this helper. local legacy_args=stv - local -A args_array=( [s]=service= [t]=template= [v]=others_var= ) + local -A args_array=( [s]=service= [t]=template= [v]=others_var=) local service local template local others_var @@ -32,30 +25,10 @@ ynh_add_supervisor_config () { local template="${template:-supervisor.service}" others_var="${others_var:-}" - finalsupervisorconf="/etc/supervisor/conf.d/$service.conf" - ynh_backup_if_checksum_is_different --file="$finalsupervisorconf" - cp ../conf/$template "$finalsupervisorconf" + [[ -z "$others_var" ]] || ynh_print_warn --message="Packagers: using --others_var is unecessary since Yunohost 4.2" - # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. - # Substitute in a nginx config file only if the variable is not empty - if [ -n "${final_path:-}" ]; then - ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalsupervisorconf" - fi - if [ -n "${app:-}" ]; then - ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$finalsupervisorconf" - fi + ynh_add_config --template="$YNH_APP_BASEDIR/conf/$template" --destination="/etc/supervisor/conf.d/$service.conf" - # Replace all other variables given as arguments - for var_to_replace in $others_var - do - # ${var_to_replace^^} make the content of the variable on upper-cases - # ${!var_to_replace} get the content of the variable named $var_to_replace - ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$finalsupervisorconf" - done - - ynh_store_file_checksum --file="$finalsupervisorconf" - - chown root: "$finalsupervisorconf" supervisorctl reread supervisorctl update } @@ -63,8 +36,9 @@ ynh_add_supervisor_config () { # Remove the dedicated supervisor config # # usage: ynh_remove_supervisor_config [--service=service] -# | arg: -s, --service= - Service name (optionnal, $app by default) +# | arg: -s, --service= - Service name (optionnal, $app by default) # +# Requires YunoHost version 2.7.2 or higher. ynh_remove_supervisor_config () { # Declare an array to define the options of this helper. local legacy_args=s @@ -86,14 +60,15 @@ ynh_remove_supervisor_config () { # Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started # -# usage: ynh_supervisor_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ] -# | arg: -n, --service_name= - Name of the service to start. Default : $app +# usage: ynh_supervisor_action [--service_name=service_name] [--action=action] [ [--line_match="line to match"] [--log_path=log_path] [--timeout=300] [--length=20] ] +# | arg: -n, --service_name= - Name of the service to start. Default : `$app` # | arg: -a, --action= - Action to perform with supervisorctl. 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: -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. +# | 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 # +# Requires YunoHost version 3.5.0 or higher. ynh_supervisor_action() { # Declare an array to define the options of this helper. local legacy_args=nalpte @@ -118,7 +93,8 @@ ynh_supervisor_action() { then local templog="$(mktemp)" # Following the starting of the app in its log - if [ "$log_path" == "systemd" ] ; then + if [ "$log_path" == "systemd" ] + then # Read the supervisor journal journalctl --unit=supervisor --follow --since=-0 --quiet > "$templog" & # Get the PID of the journalctl command @@ -144,16 +120,16 @@ ynh_supervisor_action() { # If a log is specified for this service, show also the content of this log if [ -e "$log_path" ] then - ynh_print_err --message="--" ynh_exec_err tail --lines=$length "$log_path" fi - # Fail the app script, since the service failed. - ynh_die + ynh_clean_check_starting + return 1 fi # Start the timeout and try to find line_match if [[ -n "${line_match:-}" ]] then + set +x local i=0 for i in $(seq 1 $timeout) do @@ -171,6 +147,7 @@ ynh_supervisor_action() { fi sleep 1 done + set -x if [ $i -ge 3 ]; then echo "" >&2 fi