From 575602635c6902e79121647f5e050c684967558a Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Tue, 11 Jan 2022 10:57:23 +0100 Subject: [PATCH] Fix --- scripts/_common.sh | 64 ++++++++++++++++++++++++++++++++++ scripts/backup | 1 - scripts/change_url | 1 - scripts/experimental_helper.sh | 61 -------------------------------- scripts/install | 4 +-- scripts/remove | 1 - scripts/restore | 9 ++--- scripts/upgrade | 3 +- 8 files changed, 68 insertions(+), 76 deletions(-) delete mode 100644 scripts/experimental_helper.sh diff --git a/scripts/_common.sh b/scripts/_common.sh index 38d9424..9779f45 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -106,3 +106,67 @@ set_access_settings() { ynh_app_setting_set $app skipped_regex "$excaped_domain$excaped_path/[%w-.]*/[%w-.]*/git%-receive%-pack,$excaped_domain$excaped_path/[%w-.]*/[%w-.]*/git%-upload%-pack,$excaped_domain$excaped_path/[%w-.]*/[%w-.]*/info/refs" fi } + +#================================================= + +# Delete a file checksum from the app settings +# +# $app should be defined when calling this helper +# +# usage: ynh_remove_file_checksum file +# | arg: file - The file for which the checksum will be deleted +ynh_delete_file_checksum () { + local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' + ynh_app_setting_delete $app $checksum_setting_name +} + +# Start or restart a service and follow its booting +# +# usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name] +# +# | arg: Line to match - The line to find in the log to attest the service have finished to boot. +# | arg: Log file - The log file to watch +# | arg: Service name +# /var/log/$app/$app.log will be used if no other log is defined. +# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds. +ynh_check_starting () { + local line_to_match="$1" + local service_name="${4:-$app}" + local app_log="${2:-/var/log/$service_name/$service_name.log}" + local timeout=${3:-300} + + ynh_clean_check_starting () { + # Stop the execution of tail. + kill -s 15 $pid_tail 2>&1 + ynh_secure_remove "$templog" 2>&1 + } + + echo "Starting of $service_name" >&2 + systemctl stop $service_name + local templog="$(mktemp)" + # Following the starting of the app in its log + tail -F -n0 "$app_log" > "$templog" & + # Get the PID of the tail command + local pid_tail=$! + systemctl start $service_name + + local i=0 + for i in `seq 1 $timeout` + do + # Read the log until the sentence is found, that means the app finished to start. Or run until the timeout + if grep --quiet "$line_to_match" "$templog" + then + echo "The service $service_name has correctly started." >&2 + break + fi + echo -n "." >&2 + sleep 1 + done + if [ $i -eq $timeout ] + then + echo "The service $service_name didn't fully started before the timeout." >&2 + fi + + echo "" + ynh_clean_check_starting +} \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index 772fae0..01a0761 100644 --- a/scripts/backup +++ b/scripts/backup @@ -11,7 +11,6 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Load common variables and helpers -source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh # Retrieve app settings diff --git a/scripts/change_url b/scripts/change_url index c85fa31..fb02f6c 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -11,7 +11,6 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Import common cmd -source ./experimental_helper.sh source ./_common.sh # RETRIEVE ARGUMENTS diff --git a/scripts/experimental_helper.sh b/scripts/experimental_helper.sh deleted file mode 100644 index 600a653..0000000 --- a/scripts/experimental_helper.sh +++ /dev/null @@ -1,61 +0,0 @@ -# Delete a file checksum from the app settings -# -# $app should be defined when calling this helper -# -# usage: ynh_remove_file_checksum file -# | arg: file - The file for which the checksum will be deleted -ynh_delete_file_checksum () { - local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' - ynh_app_setting_delete $app $checksum_setting_name -} - -# Start or restart a service and follow its booting -# -# usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name] -# -# | arg: Line to match - The line to find in the log to attest the service have finished to boot. -# | arg: Log file - The log file to watch -# | arg: Service name -# /var/log/$app/$app.log will be used if no other log is defined. -# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds. -ynh_check_starting () { - local line_to_match="$1" - local service_name="${4:-$app}" - local app_log="${2:-/var/log/$service_name/$service_name.log}" - local timeout=${3:-300} - - ynh_clean_check_starting () { - # Stop the execution of tail. - kill -s 15 $pid_tail 2>&1 - ynh_secure_remove "$templog" 2>&1 - } - - echo "Starting of $service_name" >&2 - systemctl stop $service_name - local templog="$(mktemp)" - # Following the starting of the app in its log - tail -F -n0 "$app_log" > "$templog" & - # Get the PID of the tail command - local pid_tail=$! - systemctl start $service_name - - local i=0 - for i in `seq 1 $timeout` - do - # Read the log until the sentence is found, that means the app finished to start. Or run until the timeout - if grep --quiet "$line_to_match" "$templog" - then - echo "The service $service_name has correctly started." >&2 - break - fi - echo -n "." >&2 - sleep 1 - done - if [ $i -eq $timeout ] - then - echo "The service $service_name didn't fully started before the timeout." >&2 - fi - - echo "" - ynh_clean_check_starting -} \ No newline at end of file diff --git a/scripts/install b/scripts/install index 76586ee..4d6f5c2 100644 --- a/scripts/install +++ b/scripts/install @@ -11,17 +11,15 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Load common variables and helpers -source ./experimental_helper.sh source ./_common.sh # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN -path_url=$(ynh_normalize_url_path $YNH_APP_ARG_PATH) +path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC # Check domain/path availability -ynh_webpath_available $domain $path_url || ynh_die "$domain is not available as domain, please use an other domain." ynh_webpath_register $app $domain $path_url # Check user parameter diff --git a/scripts/remove b/scripts/remove index 681dd01..e5deb31 100644 --- a/scripts/remove +++ b/scripts/remove @@ -8,7 +8,6 @@ source /usr/share/yunohost/helpers # Load common variables and helpers -source ./experimental_helper.sh source ./_common.sh #================================================= diff --git a/scripts/restore b/scripts/restore index 27b6ee5..734d049 100644 --- a/scripts/restore +++ b/scripts/restore @@ -11,7 +11,6 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Load common variables and helpers -source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh # Retrieve old app settings @@ -20,12 +19,8 @@ path_url=$(ynh_app_setting_get "$app" path) dbpass=$(ynh_app_setting_get "$app" mysqlpwd) admin=$(ynh_app_setting_get "$app" adminusername) -# Check domain/path availability with app helper -ynh_webpath_available $domain $path_url || ynh_die "$domain is not available as domain, please use an other domain." - # Check user parameter -ynh_user_exists "$admin" \ - || ynh_die "The chosen admin user does not exist." +ynh_user_exists "$admin" || ynh_die "The chosen admin user does not exist." # Check Final Path availability test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -49,7 +44,7 @@ ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql # Restore systemd files systemctl daemon-reload -systemctl enable "$app".service +systemctl enable "$app".service --quiet #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 82d0b6d..b182c53 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -11,12 +11,11 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Load common variables and helpers -source ./experimental_helper.sh source ./_common.sh # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) -path_url=$(ynh_normalize_url_path $(ynh_app_setting_get "$app" path)) +path_url=$(ynh_app_setting_get "$app" path) dbpass=$(ynh_app_setting_get "$app" mysqlpwd) admin=$(ynh_app_setting_get "$app" adminusername) key=$(ynh_app_setting_get "$app" secret_key)