From 6378526fe91e51b609d5f9d57fd0a2484d64f639 Mon Sep 17 00:00:00 2001 From: kay0u Date: Sat, 4 May 2019 18:46:20 +0200 Subject: [PATCH 01/16] Remove overwrite_gitlab_config, replaced by gitlab-persistent.rb --- config_panel.json | 7 ------- scripts/config | 8 -------- scripts/install | 1 - scripts/upgrade | 37 +++++++++++++------------------------ 4 files changed, 13 insertions(+), 40 deletions(-) diff --git a/config_panel.json b/config_panel.json index d30fb94..4b7ccf8 100644 --- a/config_panel.json +++ b/config_panel.json @@ -28,13 +28,6 @@ "id": "overwrite_nginx", "type": "bool", "default": true - }, - { - "name": "Overwrite the gitlab.rb config file ?", - "help": "If the file is overwritten, a backup will be created.", - "id": "overwrite_gitlab_config", - "type": "bool", - "default": true } ] }, diff --git a/scripts/config b/scripts/config index 34b490d..496829b 100644 --- a/scripts/config +++ b/scripts/config @@ -35,11 +35,6 @@ old_overwrite_nginx="$(ynh_app_setting_get $app overwrite_nginx)" old_overwrite_nginx=$(bool_to_true_false $old_overwrite_nginx) overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}" -# Overwrite gitlab.rb configuration -old_overwrite_gitlab_config="$(ynh_app_setting_get $app overwrite_gitlab_config)" -old_overwrite_gitlab_config=$(bool_to_true_false $old_overwrite_gitlab_config) -overwrite_gitlab_config="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_GITLAB_CONFIG:-$old_overwrite_gitlab_config}" - # use_web_account old_use_web_account="$(ynh_app_setting_get $app use_web_account)" old_use_web_account=$(bool_to_true_false $old_use_web_account) @@ -56,7 +51,6 @@ show_config() { echo "YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC=$is_public" echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx" - echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_GITLAB_CONFIG=$overwrite_gitlab_config" echo "YNH_CONFIG_MAIN_USERS_USE_WEB_ACCOUNT=$use_web_account" } @@ -84,8 +78,6 @@ apply_config() { # Set overwrite_nginx ynh_app_setting_set $app overwrite_nginx "$overwrite_nginx" - # Set overwrite_gitlab_config - ynh_app_setting_set $app overwrite_gitlab_config "$overwrite_gitlab_config" } #================================================= diff --git a/scripts/install b/scripts/install index 92f95e6..b456dea 100644 --- a/scripts/install +++ b/scripts/install @@ -90,7 +90,6 @@ ynh_app_setting_set $app unicorn_worker_processes $unicorn_worker_processes ynh_app_setting_set $app client_max_body_size $client_max_body_size ynh_app_setting_set $app overwrite_nginx "1" -ynh_app_setting_set $app overwrite_gitlab_config "1" #================================================= # STANDARD MODIFICATIONS diff --git a/scripts/upgrade b/scripts/upgrade index 6aebde1..2899d47 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -32,7 +32,6 @@ architecture=$(ynh_app_setting_get "$app" architecture) unicorn_worker_processes=$(ynh_app_setting_get "$app" unicorn_worker_processes) client_max_body_size=$(ynh_app_setting_get "$app" client_max_body_size) overwrite_nginx=$(ynh_app_setting_get "$app" overwrite_nginx) -overwrite_gitlab_config=$(ynh_app_setting_get "$app" overwrite_gitlab_config) #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -107,12 +106,6 @@ if [ -z "$overwrite_nginx" ]; then ynh_app_setting_set $app overwrite_nginx $overwrite_nginx fi -# If overwrite_gitlab_config doesn't exist, create it -if [ -z "$overwrite_gitlab_config" ]; then - overwrite_gitlab_config=1 - ynh_app_setting_set $app overwrite_gitlab_config $overwrite_gitlab_config -fi - # If domain doesn't exist, retrieve it if [ -z "$domain" ]; then domain=$(grep "external_url" "/etc/gitlab/gitlab.rb" | cut -d'/' -f3) # retrieve $domain from conf file @@ -184,28 +177,24 @@ ynh_install_app_dependencies $pkg_dependencies # PRECONFIGURE GITLAB #================================================= -# Overwrite the gitlab.rb configuration only if it's allowed -if [ $overwrite_gitlab_config -eq 1 ] -then - ynh_print_info "Preconfigure gitlab..." +ynh_print_info "Preconfigure gitlab..." - ynh_backup_if_checksum_is_different "$config_path/gitlab.rb" +ynh_backup_if_checksum_is_different "$config_path/gitlab.rb" - mkdir -p $config_path +mkdir -p $config_path - cp -f ../conf/gitlab.rb "$config_path/gitlab.rb" - ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+") +cp -f ../conf/gitlab.rb "$config_path/gitlab.rb" +ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+") - ynh_replace_string "__GENERATED_EXTERNAL_URL__" "https://$domain${path_url%/}" "$config_path/gitlab.rb" - ynh_replace_string "__PORT__" "$port" "$config_path/gitlab.rb" - ynh_replace_string "__UNICORN_PORT__" "$portUnicorn" "$config_path/gitlab.rb" - ynh_replace_string "__UNICORN_WORKER_PROCESSES__" "$unicorn_worker_processes" "$config_path/gitlab.rb" - ynh_replace_string "__CLIENT_MAX_BODY_SIZE__" "$client_max_body_size" "$config_path/gitlab.rb" - ynh_replace_string "__SSH_PORT__" "$ssh_port" "$config_path/gitlab.rb" - ynh_replace_string "__SIDEKIQ_PORT__" "$portSidekiq" "$config_path/gitlab.rb" +ynh_replace_string "__GENERATED_EXTERNAL_URL__" "https://$domain${path_url%/}" "$config_path/gitlab.rb" +ynh_replace_string "__PORT__" "$port" "$config_path/gitlab.rb" +ynh_replace_string "__UNICORN_PORT__" "$portUnicorn" "$config_path/gitlab.rb" +ynh_replace_string "__UNICORN_WORKER_PROCESSES__" "$unicorn_worker_processes" "$config_path/gitlab.rb" +ynh_replace_string "__CLIENT_MAX_BODY_SIZE__" "$client_max_body_size" "$config_path/gitlab.rb" +ynh_replace_string "__SSH_PORT__" "$ssh_port" "$config_path/gitlab.rb" +ynh_replace_string "__SIDEKIQ_PORT__" "$portSidekiq" "$config_path/gitlab.rb" - ynh_store_file_checksum "$config_path/gitlab.rb" -fi +ynh_store_file_checksum "$config_path/gitlab.rb" touch "$config_path/gitlab-persistent.rb" chown admin: "$config_path/gitlab-persistent.rb" From 4c45e7cb65f3da2e14b695192a735a8b30010767 Mon Sep 17 00:00:00 2001 From: Kayou Date: Mon, 6 May 2019 21:17:27 +0200 Subject: [PATCH 02/16] Add swap --- manifest.json | 2 +- scripts/_common.sh | 226 +++++++++++++++++++++++++-------------------- scripts/install | 24 ++++- scripts/remove | 4 + scripts/restore | 23 +++++ scripts/upgrade | 23 +++++ 6 files changed, 202 insertions(+), 100 deletions(-) diff --git a/manifest.json b/manifest.json index c3015c2..d932cc7 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,7 @@ "email": "pierre@kayou.io" }, "requirements": { - "yunohost": ">> 3.3.0" + "yunohost": ">= 3.5.0" }, "multi_instance": false, "services": [ diff --git a/scripts/_common.sh b/scripts/_common.sh index 54d9789..cc30127 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -33,110 +33,140 @@ bool_to_true_false () { } #================================================= -# WAIT +# EXPERIMENTAL HELPERS #================================================= -# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started + +# Add swap # -# usage: ynh_systemd_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 -# | 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 -ynh_systemd_action() { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= ) - local service_name - local action - local line_match - local length - local log_path - local timeout +# usage: ynh_add_swap --size=SWAP in Mb +# | arg: -s, --size= - Amount of SWAP to add in Mb. +ynh_add_swap () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [s]=size= ) + local size + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + local swap_max_size=$(( $size * 1024 )) - local service_name="${service_name:-$app}" - local action=${action:-start} - local log_path="${log_path:-/var/log/$service_name/$service_name.log}" - local length=${length:-20} - local timeout=${timeout:-300} + local free_space=$(df --output=avail / | sed 1d) + # Because we don't want to fill the disk with a swap file, divide by 2 the available space. + local usable_space=$(( $free_space / 2 )) - # Start to read the log - if [[ -n "${line_match:-}" ]] - then - local templog="$(mktemp)" - # Following the starting of the app in its log - 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" 2>&1 & - # Get the PID of the tail command - local pid_tail=$! - fi - fi + # Compare the available space with the size of the swap. + # And set a acceptable size from the request + if [ $usable_space -ge $swap_max_size ] + then + local swap_size=$swap_max_size + elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] + then + local swap_size=$(( $swap_max_size / 2 )) + elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] + then + local swap_size=$(( $swap_max_size / 3 )) + elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] + then + local swap_size=$(( $swap_max_size / 4 )) + else + echo "Not enough space left for a swap file" >&2 + local swap_size=0 + fi - ynh_print_info --message="${action^} the service $service_name" - - # Use reload-or-restart instead of reload. So it wouldn't fail if the service isn't running. - if [ "$action" == "reload" ]; then - action="reload-or-restart" - fi - - systemctl $action $service_name \ - || ( journalctl --no-pager --lines=$length -u $service_name >&2 \ - ; test -e "$log_path" && echo "--" >&2 && tail --lines=$length "$log_path" >&2 \ - ; false ) - - # Start the timeout and try to find line_match - if [[ -n "${line_match:-}" ]] - then - 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_match" "$templog" - then - ynh_print_info --message="The service $service_name has correctly started." - break - fi - if [ $i -eq 3 ]; then - echo -n "Please wait, the service $service_name is ${action}ing" >&2 - fi - if [ $i -ge 3 ]; then - echo -n "." >&2 - fi - sleep 1 - done - if [ $i -ge 3 ]; then - echo "" >&2 - fi - if [ $i -eq $timeout ] - then - ynh_print_warn --message="The service $service_name didn't fully started before the timeout." - ynh_print_warn --message="Please find here an extract of the end of the log of the service $service_name:" - journalctl --no-pager --lines=$length -u $service_name >&2 - test -e "$log_path" && echo "--" >&2 && tail --lines=$length "$log_path" >&2 - fi - ynh_clean_check_starting - fi + # If there's enough space for a swap, and no existing swap here + if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ] + then + # Preallocate space for the swap file + fallocate -l ${swap_size}K /swap_$app + chmod 0600 /swap_$app + # Create the swap + mkswap /swap_$app + # And activate it + swapon /swap_$app + # Then add an entry in fstab to load this swap at each boot. + echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab + fi } -# Clean temporary process and file used by ynh_check_starting -# (usually used in ynh_clean_setup scripts) +ynh_del_swap () { + # If there a swap at this place + if [ -e /swap_$app ] + then + # Clean the fstab + sed -i "/#Swap added by $app/d" /etc/fstab + # Desactive the swap file + swapoff /swap_$app + # And remove it + rm /swap_$app + fi +} + +# Check the amount of available RAM # -# usage: ynh_clean_check_starting -ynh_clean_check_starting () { - # Stop the execution of tail. - kill -s 15 $pid_tail 2>&1 - ynh_secure_remove "$templog" 2>&1 -} \ No newline at end of file +# usage: ynh_check_ram [--required=RAM required in Mb] [--no_swap|--only_swap] [--free_ram] +# | arg: -r, --required= - Amount of RAM required in Mb. The helper will return 0 is there's enough RAM, or 1 otherwise. +# If --required isn't set, the helper will print the amount of RAM, in Mb. +# | arg: -s, --no_swap - Ignore swap +# | arg: -o, --only_swap - Ignore real RAM, consider only swap. +# | arg: -f, --free_ram - Count only free RAM, not the total amount of RAM available. +ynh_check_ram () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [r]=required= [s]=no_swap [o]=only_swap [f]=free_ram ) + local required + local no_swap + local only_swap + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + required=${required:-} + no_swap=${no_swap:-0} + only_swap=${only_swap:-0} + + local total_ram=$(vmstat --stats --unit M | grep "total memory" | awk '{print $1}') + local total_swap=$(vmstat --stats --unit M | grep "total swap" | awk '{print $1}') + local total_ram_swap=$(( total_ram + total_swap )) + + local free_ram=$(vmstat --stats --unit M | grep "free memory" | awk '{print $1}') + local free_swap=$(vmstat --stats --unit M | grep "free swap" | awk '{print $1}') + local free_ram_swap=$(( free_ram + free_swap )) + + # Use the total amount of ram + local ram=$total_ram_swap + if [ $free_ram -eq 1 ] + then + # Use the total amount of free ram + ram=$free_ram_swap + if [ $no_swap -eq 1 ] + then + # Use only the amount of free ram + ram=$free_ram + elif [ $only_swap -eq 1 ] + then + # Use only the amount of free swap + ram=$free_swap + fi + else + if [ $no_swap -eq 1 ] + then + # Use only the amount of free ram + ram=$total_ram + elif [ $only_swap -eq 1 ] + then + # Use only the amount of free swap + ram=$total_swap + fi + fi + + if [ -n "$required" ] + then + # Return 1 if the amount of ram isn't enough. + if [ $ram -lt $required ] + then + return 1 + else + return 0 + fi + + # If no RAM is required, return the amount of available ram. + else + echo $ram + fi +} diff --git a/scripts/install b/scripts/install index b456dea..4e7e75c 100644 --- a/scripts/install +++ b/scripts/install @@ -58,7 +58,7 @@ fi unicorn_worker_processes=$(($(nproc) + 1 )) # If the server has at least 2GB of RAM -if [ $(free -g --si | grep Mem: | awk '{print $2}') -ge 2 ]; then +if [ $(ynh_check_ram --no_swap) -ge 2000 ]; then # Min 3 worker processes unicorn_worker_processes=$(($unicorn_worker_processes>3?$unicorn_worker_processes:3)) else @@ -114,6 +114,28 @@ ynh_print_info "Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies +#================================================= +# ADD SWAP IF NEEDED +#================================================= + +total_memory=$(ynh_check_ram) +total_swap=$(ynh_check_ram --only_swap) +swap_needed=0 + +# https://docs.gitlab.com/ee/install/requirements.html#memory +if [ $total_memory -lt 8000 ]; then + # Need a minimum of 8Gb of memory + swap_needed=$((8000 - $total_memory)) +fi + +# Need at least 2Gb of swap +if [ $(($total_swap + $swap_needed)) -lt 2000 ]; then + swap_needed=$((2000 - $total_swap)) +fi + +ynh_print_info "Adding $swap_needed to swap..." +ynh_add_swap $swap_needed + #================================================= # PRECONFIGURE GITLAB #================================================= diff --git a/scripts/remove b/scripts/remove index 652f398..b1ae6bb 100644 --- a/scripts/remove +++ b/scripts/remove @@ -99,6 +99,10 @@ ynh_secure_remove "/var/opt/$app" # Remove the log files ynh_secure_remove "/var/log/$app" +# Remove swap + +ynh_del_swap + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 42cd9f8..c070f16 100644 --- a/scripts/restore +++ b/scripts/restore @@ -61,6 +61,29 @@ ynh_print_info "Reinstalling dependencies..." # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies +#================================================= +# ADD SWAP IF NEEDED +#================================================= +ynh_print_info "Adding swap..." + +total_memory=$(ynh_check_ram) +total_swap=$(ynh_check_ram --only_swap) +swap_needed=0 + +# https://docs.gitlab.com/ee/install/requirements.html#memory +if [ $total_memory -lt 8000 ]; then + # Need a minimum of 8Gb of memory + swap_needed=$((8000 - $total_memory)) +fi + +# Need at least 2Gb of swap +if [ $(($total_swap + $swap_needed)) -lt 2000 ]; then + swap_needed=$((2000 - $total_swap)) +fi + +ynh_print_info "Adding $swap_needed to swap..." +ynh_add_swap $swap_needed + #================================================= # RESTORE CONF FILES #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 2899d47..397109e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -173,6 +173,29 @@ ynh_print_info "Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies +#================================================= +# ADD SWAP IF NEEDED +#================================================= +ynh_print_info "Adding swap..." + +total_memory=$(ynh_check_ram) +total_swap=$(ynh_check_ram --only_swap) +swap_needed=0 + +# https://docs.gitlab.com/ee/install/requirements.html#memory +if [ $total_memory -lt 8000 ]; then + # Need a minimum of 8Gb of memory + swap_needed=$((8000 - $total_memory)) +fi + +# Need at least 2Gb of swap +if [ $(($total_swap + $swap_needed)) -lt 2000 ]; then + swap_needed=$((2000 - $total_swap)) +fi + +ynh_print_info "Adding $swap_needed to swap..." +ynh_add_swap $swap_needed + #================================================= # PRECONFIGURE GITLAB #================================================= From f925a143b926e9334be7fed5203766203eed708f Mon Sep 17 00:00:00 2001 From: Kayou Date: Tue, 7 May 2019 00:33:40 +0200 Subject: [PATCH 03/16] Update check_process --- check_process | 9 --------- 1 file changed, 9 deletions(-) diff --git a/check_process b/check_process index 07aec4a..45a2323 100644 --- a/check_process +++ b/check_process @@ -21,16 +21,7 @@ port_already_use=1 (8080) change_url=1 ;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto - Level 4=auto Level 5=auto - Level 6=auto - Level 7=auto - Level 8=auto - Level 9=0 - Level 10=0 ;;; Options Email= Notification=none From d5e44d9769c6ea8fe95a609a9a8bb98d083e6577 Mon Sep 17 00:00:00 2001 From: Kayou Date: Tue, 7 May 2019 00:37:07 +0200 Subject: [PATCH 04/16] Fix swap values --- scripts/install | 12 ++++++------ scripts/restore | 12 ++++++------ scripts/upgrade | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/scripts/install b/scripts/install index 4e7e75c..940c2c2 100644 --- a/scripts/install +++ b/scripts/install @@ -123,14 +123,14 @@ total_swap=$(ynh_check_ram --only_swap) swap_needed=0 # https://docs.gitlab.com/ee/install/requirements.html#memory -if [ $total_memory -lt 8000 ]; then - # Need a minimum of 8Gb of memory - swap_needed=$((8000 - $total_memory)) +if [ $total_memory -lt 8192 ]; then + # Need a minimum of 8Gbo of memory + swap_needed=$((8192 - $total_memory)) fi -# Need at least 2Gb of swap -if [ $(($total_swap + $swap_needed)) -lt 2000 ]; then - swap_needed=$((2000 - $total_swap)) +# Need at least 2Go of swap +if [ $(($total_swap + $swap_needed)) -lt 2048 ]; then + swap_needed=$((2048 - $total_swap)) fi ynh_print_info "Adding $swap_needed to swap..." diff --git a/scripts/restore b/scripts/restore index c070f16..965db39 100644 --- a/scripts/restore +++ b/scripts/restore @@ -71,14 +71,14 @@ total_swap=$(ynh_check_ram --only_swap) swap_needed=0 # https://docs.gitlab.com/ee/install/requirements.html#memory -if [ $total_memory -lt 8000 ]; then - # Need a minimum of 8Gb of memory - swap_needed=$((8000 - $total_memory)) +if [ $total_memory -lt 8192 ]; then + # Need a minimum of 8Gbo of memory + swap_needed=$((8192 - $total_memory)) fi -# Need at least 2Gb of swap -if [ $(($total_swap + $swap_needed)) -lt 2000 ]; then - swap_needed=$((2000 - $total_swap)) +# Need at least 2Go of swap +if [ $(($total_swap + $swap_needed)) -lt 2048 ]; then + swap_needed=$((2048 - $total_swap)) fi ynh_print_info "Adding $swap_needed to swap..." diff --git a/scripts/upgrade b/scripts/upgrade index 397109e..4c14c3f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -183,14 +183,14 @@ total_swap=$(ynh_check_ram --only_swap) swap_needed=0 # https://docs.gitlab.com/ee/install/requirements.html#memory -if [ $total_memory -lt 8000 ]; then - # Need a minimum of 8Gb of memory - swap_needed=$((8000 - $total_memory)) +if [ $total_memory -lt 8192 ]; then + # Need a minimum of 8Gbo of memory + swap_needed=$((8192 - $total_memory)) fi -# Need at least 2Gb of swap -if [ $(($total_swap + $swap_needed)) -lt 2000 ]; then - swap_needed=$((2000 - $total_swap)) +# Need at least 2Go of swap +if [ $(($total_swap + $swap_needed)) -lt 2048 ]; then + swap_needed=$((2048 - $total_swap)) fi ynh_print_info "Adding $swap_needed to swap..." From 9e7df456ee062d37699de296ff818ffe252277a4 Mon Sep 17 00:00:00 2001 From: Kayou Date: Tue, 7 May 2019 00:51:34 +0200 Subject: [PATCH 05/16] Typo --- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 940c2c2..eb14748 100644 --- a/scripts/install +++ b/scripts/install @@ -124,7 +124,7 @@ swap_needed=0 # https://docs.gitlab.com/ee/install/requirements.html#memory if [ $total_memory -lt 8192 ]; then - # Need a minimum of 8Gbo of memory + # Need a minimum of 8Go of memory swap_needed=$((8192 - $total_memory)) fi diff --git a/scripts/restore b/scripts/restore index 965db39..d107441 100644 --- a/scripts/restore +++ b/scripts/restore @@ -72,7 +72,7 @@ swap_needed=0 # https://docs.gitlab.com/ee/install/requirements.html#memory if [ $total_memory -lt 8192 ]; then - # Need a minimum of 8Gbo of memory + # Need a minimum of 8Go of memory swap_needed=$((8192 - $total_memory)) fi diff --git a/scripts/upgrade b/scripts/upgrade index 4c14c3f..66a19fb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -184,7 +184,7 @@ swap_needed=0 # https://docs.gitlab.com/ee/install/requirements.html#memory if [ $total_memory -lt 8192 ]; then - # Need a minimum of 8Gbo of memory + # Need a minimum of 8Go of memory swap_needed=$((8192 - $total_memory)) fi From eb564f9ad9cb09c00a071c862a10f343a008f54e Mon Sep 17 00:00:00 2001 From: Kay0u Date: Thu, 9 May 2019 00:01:27 +0200 Subject: [PATCH 06/16] Update ynh_add_swap helper --- scripts/_common.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/_common.sh b/scripts/_common.sh index cc30127..bac71f7 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -36,6 +36,20 @@ bool_to_true_false () { # EXPERIMENTAL HELPERS #================================================= +# Check if the device of the main mountpoint "/" is an SD card +# +# return 1 if it's an SD card, else 0 +_ynh_is_main_device_is_sd_card () { + local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) + + if echo $main_device | grep --quiet "mmc" && [ $(cat /sys/block/$main_device/queue/rotational) -eq 0 ] + then + return 1 + else + return 0 + fi +} + # Add swap # # usage: ynh_add_swap --size=SWAP in Mb @@ -53,6 +67,14 @@ ynh_add_swap () { # Because we don't want to fill the disk with a swap file, divide by 2 the available space. local usable_space=$(( $free_space / 2 )) + SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} + + # Swap on SD card only if it's is specified + if [ _ynh_is_main_device_is_sd_card ] && [ "$SD_CARD_CAN_SWAP" == "0" ] + then + return + fi + # Compare the available space with the size of the swap. # And set a acceptable size from the request if [ $usable_space -ge $swap_max_size ] From a9904228e5dd97dc5c41ff19e115d7e07817dc8e Mon Sep 17 00:00:00 2001 From: Kay0u Date: Thu, 9 May 2019 01:13:48 +0200 Subject: [PATCH 07/16] Normalization from example_ynh --- manifest.json | 2 +- scripts/actions/public_private | 12 ++-- scripts/actions/web_account | 6 +- scripts/backup | 28 ++++----- scripts/change_url | 63 ++++++++----------- scripts/config | 8 +-- scripts/install | 106 +++++++++++++++---------------- scripts/remove | 38 +++++------ scripts/restore | 68 ++++++++++---------- scripts/upgrade | 111 ++++++++++++++++----------------- 10 files changed, 215 insertions(+), 227 deletions(-) diff --git a/manifest.json b/manifest.json index c3015c2..d932cc7 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,7 @@ "email": "pierre@kayou.io" }, "requirements": { - "yunohost": ">> 3.3.0" + "yunohost": ">= 3.5.0" }, "multi_instance": false, "services": [ diff --git a/scripts/actions/public_private b/scripts/actions/public_private index 8c683f6..9559106 100644 --- a/scripts/actions/public_private +++ b/scripts/actions/public_private @@ -26,7 +26,7 @@ app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} # CHECK IF AN ACTION HAS TO BE DONE #================================================= -is_public_old=$(ynh_app_setting_get $app is_public) +is_public_old=$(ynh_app_setting_get --app=$app --key=is_public) if [ $is_public -eq $is_public_old ] then @@ -43,27 +43,27 @@ if [ $is_public -eq 0 ]; then else public_private="public" fi -ynh_print_info --message="Moving the application to $public_private..." +ynh_script_progression --message=--message="Moving the application to $public_private..." --time # Make app public if necessary if [ $is_public -eq 0 ]; then ynh_app_setting_delete $app unprotected_uris else # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi -ynh_print_info --message="Reconfiguring SSOwat..." +ynh_script_progression --message=--message="Reconfiguring SSOwat..." --time # Regen ssowat configuration yunohost app ssowatconf # Update the config of the app -ynh_app_setting_set $app is_public $is_public +ynh_app_setting_set --app=$app --key=is_public --value=$is_public #================================================= # RELOAD NGINX #================================================= -ynh_print_info --message="Reloading nginx web server..." +ynh_script_progression --message=--message="Reloading nginx web server..." --time ynh_systemd_action --action=reload --service_name=nginx diff --git a/scripts/actions/web_account b/scripts/actions/web_account index b7edfbe..629710d 100644 --- a/scripts/actions/web_account +++ b/scripts/actions/web_account @@ -26,7 +26,7 @@ app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} # CHECK IF AN ACTION HAS TO BE DONE #================================================= -use_web_account_old=$(ynh_app_setting_get $app use_web_account) +use_web_account_old=$(ynh_app_setting_get --app=$app --key=use_web_account) if [ $use_web_account -eq $use_web_account_old ] then @@ -43,12 +43,12 @@ if [ $use_web_account -eq 0 ]; then else web_account="Disable" fi -ynh_print_info --message="$web_account web user creation..." +ynh_script_progression --message=--message="$web_account web user creation..." --time echo "ApplicationSetting.last.update_attributes(password_authentication_enabled_for_web: $use_web_account, signup_enabled: $use_web_account)" | gitlab-rails console # Update the config of the app -ynh_app_setting_set $app use_web_account $use_web_account +ynh_app_setting_set --app=$app --key=use_web_account --value=$use_web_account #================================================= # END OF SCRIPT diff --git a/scripts/backup b/scripts/backup index d1284e0..f38d75a 100644 --- a/scripts/backup +++ b/scripts/backup @@ -24,48 +24,48 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --time app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) -config_path=$(ynh_app_setting_get $app config_path) -domain=$(ynh_app_setting_get $app domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +config_path=$(ynh_app_setting_get --app=$app --key=config_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) #================================================= # STANDARD BACKUP STEPS #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_print_info "Backing up nginx web server configuration..." +ynh_script_progression --message="Backing up nginx web server configuration..." --time -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP GITLAB DATABASE #================================================= -ynh_print_info "Backuping of Gitlab..." +ynh_script_progression --message="Backuping of Gitlab..." --time # Use gitlab-rake to backup gitlab-rake gitlab:backup:create > backup.log -# Searching in backup logs the +# Searching in backup logs the name of the backup archive created last_backup=$(grep _gitlab_backup.tar backup.log | cut -d' ' -f4) mv "/var/opt/$app/backups/$last_backup" "/var/opt/$app/backups/last_gitlab_backup.tar" -ynh_backup "/var/opt/$app/backups/last_gitlab_backup.tar" +ynh_backup --src_path="/var/opt/$app/backups/last_gitlab_backup.tar" #================================================= # BACKUP CONF FILES #================================================= -ynh_print_info "Backuping configuration files of Gitlab..." +ynh_script_progression --message="Backuping configuration files of Gitlab..." --time -ynh_backup "$config_path/gitlab-secrets.json" -ynh_backup "$config_path/gitlab.rb" -ynh_backup "$config_path/gitlab-persistent.rb" +ynh_backup --src_path="$config_path/gitlab-secrets.json" +ynh_backup --src_path="$config_path/gitlab.rb" +ynh_backup --src_path="$config_path/gitlab-persistent.rb" #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last diff --git a/scripts/change_url b/scripts/change_url index 2a220cf..c16fe04 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,25 +24,16 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --time # Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get $app final_path) -config_path=$(ynh_app_setting_get $app config_path) -port=$(ynh_app_setting_get "$app" web_port) -portUnicorn=$(ynh_app_setting_get "$app" unicorn_port) -portSidekiq=$(ynh_app_setting_get "$app" sidekiq_port) -unicorn_worker_processes=$(ynh_app_setting_get "$app" unicorn_worker_processes) -client_max_body_size=$(ynh_app_setting_get "$app" client_max_body_size) - -#================================================= -# CHECK THE SYNTAX OF THE PATHS -#================================================= - -test -n "$old_path" || old_path="/" -test -n "$new_path" || new_path="/" -new_path=$(ynh_normalize_url_path $new_path) -old_path=$(ynh_normalize_url_path $old_path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +config_path=$(ynh_app_setting_get --app=$app --key=config_path) +port=$(ynh_app_setting_get --app="$app" --key=web_port) +portUnicorn=$(ynh_app_setting_get --app="$app" --key=unicorn_port) +portSidekiq=$(ynh_app_setting_get --app="$app" --key=sidekiq_port) +unicorn_worker_processes=$(ynh_app_setting_get --app="$app" --key=unicorn_worker_processes) +client_max_body_size=$(ynh_app_setting_get --app="$app" --key=client_max_body_size) #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED @@ -63,12 +54,12 @@ fi #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_print_info "Updating nginx web server configuration..." +ynh_script_progression --message="Updating nginx web server configuration..." --time nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf if [ $change_path -eq 1 ]; then - ynh_print_info "Changing path..." + ynh_script_progression --message="Changing path..." --time #doc in: https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab @@ -76,7 +67,7 @@ if [ $change_path -eq 1 ]; then gitlab-ctl stop sidekiq # Make a backup of the original nginx config file if modified - ynh_backup_if_checksum_is_different "$nginx_conf_path" + ynh_backup_if_checksum_is_different --file="$nginx_conf_path" # Set global variables for nginx helper domain="$old_domain" path_url="$new_path" @@ -86,13 +77,13 @@ fi # Change the domain for nginx if [ $change_domain -eq 1 ]; then - ynh_print_info "Changing domain..." + ynh_script_progression --message="Changing domain..." --time # Delete file checksum for the old conf file location - ynh_delete_file_checksum "$nginx_conf_path" + ynh_delete_file_checksum --file="$nginx_conf_path" mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf # Store file checksum for the new config file location - ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #================================================= @@ -100,9 +91,9 @@ fi #================================================= # CONFIGURE GITLAB #================================================= -ynh_print_info "Configure gitlab..." +ynh_script_progression --message="Configure gitlab..." --time -ynh_backup_if_checksum_is_different "$config_path/gitlab.rb" +ynh_backup_if_checksum_is_different --file="$config_path/gitlab.rb" mkdir -p $config_path @@ -112,15 +103,15 @@ ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+") domain="$new_domain" path_url="$new_path" -ynh_replace_string "__GENERATED_EXTERNAL_URL__" "https://$domain${path_url%/}" "$config_path/gitlab.rb" -ynh_replace_string "__PORT__" "$port" "$config_path/gitlab.rb" -ynh_replace_string "__UNICORN_PORT__" "$portUnicorn" "$config_path/gitlab.rb" -ynh_replace_string "__UNICORN_WORKER_PROCESSES__" "$unicorn_worker_processes" "$config_path/gitlab.rb" -ynh_replace_string "__CLIENT_MAX_BODY_SIZE__" "$client_max_body_size" "$config_path/gitlab.rb" -ynh_replace_string "__SSH_PORT__" "$ssh_port" "$config_path/gitlab.rb" -ynh_replace_string "__SIDEKIQ_PORT__" "$portSidekiq" "$config_path/gitlab.rb" +ynh_replace_string --match_string="__GENERATED_EXTERNAL_URL__" --replace_string="https://$domain${path_url%/}" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__UNICORN_PORT__" --replace_string="$portUnicorn" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__UNICORN_WORKER_PROCESSES__" --replace_string="$unicorn_worker_processes" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__CLIENT_MAX_BODY_SIZE__" --replace_string="$client_max_body_size" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__SSH_PORT__" --replace_string="$ssh_port" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__SIDEKIQ_PORT__" --replace_string="$portSidekiq" --target_file="$config_path/gitlab.rb" -ynh_store_file_checksum "$config_path/gitlab.rb" +ynh_store_file_checksum --file="$config_path/gitlab.rb" #================================================= # RECONFIGURE GITLAB @@ -136,7 +127,7 @@ fi #================================================= # WAITING GITLAB #================================================= -ynh_print_info "Waiting for gitlab..." +ynh_script_progression --message="Waiting for gitlab..." --time # Action status to just wait the service ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --line_match="adopted" --timeout=3600 @@ -146,7 +137,7 @@ ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path=" #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." --time ynh_systemd_action --action=reload --service_name=nginx @@ -154,4 +145,4 @@ ynh_systemd_action --action=reload --service_name=nginx # END OF SCRIPT #================================================= -ynh_print_info "Change of URL completed for $app" +ynh_script_progression --message="Change of URL completed for $app" --time --last diff --git a/scripts/config b/scripts/config index 496829b..f66658d 100644 --- a/scripts/config +++ b/scripts/config @@ -26,17 +26,17 @@ app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} # Otherwise, keep the value from the app config. # is_public -old_is_public="$(ynh_app_setting_get $app is_public)" +old_is_public="$(ynh_app_setting_get --app=$app --key=is_public)" old_is_public=$(bool_to_true_false $old_is_public) is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}" # Overwrite nginx configuration -old_overwrite_nginx="$(ynh_app_setting_get $app overwrite_nginx)" +old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)" old_overwrite_nginx=$(bool_to_true_false $old_overwrite_nginx) overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}" # use_web_account -old_use_web_account="$(ynh_app_setting_get $app use_web_account)" +old_use_web_account="$(ynh_app_setting_get --app=$app --key=use_web_account)" old_use_web_account=$(bool_to_true_false $old_use_web_account) use_web_account="${YNH_CONFIG_MAIN_USERS_USE_WEB_ACCOUNT:-$old_use_web_account}" @@ -77,7 +77,7 @@ apply_config() { fi # Set overwrite_nginx - ynh_app_setting_set $app overwrite_nginx "$overwrite_nginx" + ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx" } #================================================= diff --git a/scripts/install b/scripts/install index b456dea..e392906 100644 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_secure_remove "$tempdir" 2>&1 + ynh_exec_warn_less ynh_secure_remove --file="$tempdir" ynh_clean_check_starting } @@ -36,11 +36,11 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_print_info "Validating installation parameters..." +ynh_script_progression --message="Validating installation parameters..." --time config_path=/etc/$app final_path=/opt/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Detect the system architecture if [ -n "$(uname -m | grep 64)" ]; then @@ -50,7 +50,7 @@ elif [ -n "$(uname -m | grep 86)" ]; then elif [ -n "$(uname -m | grep arm)" ]; then architecture="arm" else - ynh_die "Unable to detect your achitecture, please open a bug describing \ + ynh_die --message="Unable to detect your achitecture, please open a bug describing \ your hardware and the result of the command \"uname -m\"." 1 fi @@ -69,55 +69,53 @@ fi # Could be an option? client_max_body_size="250m" -path_url=$(ynh_normalize_url_path $path_url) - # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_print_info "Storing installation settings..." +ynh_script_progression --message="Storing installation settings..." --time -ynh_app_setting_set $app admin $admin -ynh_app_setting_set $app path_url $path_url -ynh_app_setting_set $app is_public $is_public -ynh_app_setting_set $app use_web_account $use_web_account -ynh_app_setting_set $app final_path $final_path -ynh_app_setting_set $app config_path $config_path -ynh_app_setting_set $app architecture $architecture -ynh_app_setting_set $app unicorn_worker_processes $unicorn_worker_processes -ynh_app_setting_set $app client_max_body_size $client_max_body_size +ynh_app_setting_set --app=$app --key=admin --value=$admin +ynh_app_setting_set --app=$app --key=path_url --value=$path_url +ynh_app_setting_set --app=$app --key=is_public --value=$is_public +ynh_app_setting_set --app=$app --key=use_web_account --value=$use_web_account +ynh_app_setting_set --app=$app --key=final_path --value=$final_path +ynh_app_setting_set --app=$app --key=config_path --value=$config_path +ynh_app_setting_set --app=$app --key=architecture --value=$architecture +ynh_app_setting_set --app=$app --key=unicorn_worker_processes --value=$unicorn_worker_processes +ynh_app_setting_set --app=$app --key=client_max_body_size --value=$client_max_body_size -ynh_app_setting_set $app overwrite_nginx "1" +ynh_app_setting_set --app=$app --key=overwrite_nginx --value="1" #================================================= # STANDARD MODIFICATIONS #================================================= # FIND A PORT #================================================= -ynh_print_info "Find internal port..." +ynh_script_progression --message="Find internal port..." --time # Find free ports -port=$(ynh_find_port 8080) -portUnicorn=$(ynh_find_port $(($port + 1))) -portSidekiq=$(ynh_find_port $(($portUnicorn + 1))) +port=$(ynh_find_port --port=8080) +portUnicorn=$(ynh_find_port --port=$(($port + 1))) +portSidekiq=$(ynh_find_port --port=$(($portUnicorn + 1))) -ynh_app_setting_set $app web_port $port -ynh_app_setting_set $app unicorn_port $portUnicorn -ynh_app_setting_set $app sidekiq_port $portSidekiq +ynh_app_setting_set --app=$app --key=web_port --value=$port +ynh_app_setting_set --app=$app --key=unicorn_port --value=$portUnicorn +ynh_app_setting_set --app=$app --key=sidekiq_port --value=$portSidekiq #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_print_info "Installing dependencies..." +ynh_script_progression --message="Installing dependencies..." --time ynh_install_app_dependencies $pkg_dependencies #================================================= # PRECONFIGURE GITLAB #================================================= -ynh_print_info "Preconfigure gitlab..." +ynh_script_progression --message="Preconfigure gitlab..." --time mkdir -p $config_path @@ -127,35 +125,35 @@ chown admin: "$config_path/gitlab-persistent.rb" cp -f ../conf/gitlab.rb "$config_path/gitlab.rb" ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+") -ynh_replace_string "__GENERATED_EXTERNAL_URL__" "https://$domain${path_url%/}" "$config_path/gitlab.rb" -ynh_replace_string "__PORT__" "$port" "$config_path/gitlab.rb" -ynh_replace_string "__UNICORN_PORT__" "$portUnicorn" "$config_path/gitlab.rb" -ynh_replace_string "__UNICORN_WORKER_PROCESSES__" "$unicorn_worker_processes" "$config_path/gitlab.rb" -ynh_replace_string "__CLIENT_MAX_BODY_SIZE__" "$client_max_body_size" "$config_path/gitlab.rb" -ynh_replace_string "__SSH_PORT__" "$ssh_port" "$config_path/gitlab.rb" -ynh_replace_string "__SIDEKIQ_PORT__" "$portSidekiq" "$config_path/gitlab.rb" +ynh_replace_string --match_string="__GENERATED_EXTERNAL_URL__" --replace_string="https://$domain${path_url%/}" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__UNICORN_PORT__" --replace_string="$portUnicorn" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__UNICORN_WORKER_PROCESSES__" --replace_string="$unicorn_worker_processes" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__CLIENT_MAX_BODY_SIZE__" --replace_string="$client_max_body_size" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__SSH_PORT__" --replace_string="$ssh_port" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__SIDEKIQ_PORT__" --replace_string="$portSidekiq" --target_file="$config_path/gitlab.rb" #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= -ynh_store_file_checksum "$config_path/gitlab.rb" +ynh_store_file_checksum --file="$config_path/gitlab.rb" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_print_info "Setting up source files..." +ynh_script_progression --message="Setting up source files..." --time update_src_version() { source ./upgrade.d/upgrade.last.sh cp ../conf/$architecture.src.default ../conf/$architecture.src - ynh_replace_string "__VERSION__" "$gitlab_version" "../conf/$architecture.src" - ynh_replace_string "__SOURCE_FILENAME__" "$gitlab_filename" "../conf/$architecture.src" + ynh_replace_string --match_string="__VERSION__" --replace_string="$gitlab_version" --target_file="../conf/$architecture.src" + ynh_replace_string --match_string="__SOURCE_FILENAME__" --replace_string="$gitlab_filename" --target_file="../conf/$architecture.src" if [ $architecture = "x86-64" ]; then - ynh_replace_string "__SHA256_SUM__" "$gitlab_x86_64_source_sha256" "../conf/$architecture.src" + ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_x86_64_source_sha256" --target_file="../conf/$architecture.src" elif [ $architecture = "arm" ]; then - ynh_replace_string "__SHA256_SUM__" "$gitlab_arm_source_sha256" "../conf/$architecture.src" + ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_arm_source_sha256" --target_file="../conf/$architecture.src" fi } @@ -163,21 +161,21 @@ update_src_version tempdir="$(mktemp -d)" -ynh_setup_source $tempdir $architecture +ynh_setup_source --dest_dir=$tempdir --source_id=$architecture if IS_PACKAGE_CHECK; then - if ! dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env - ynh_replace_string "command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" "command \"cat \/etc\/sysctl.conf\"" "$final_path/embedded/cookbooks/package/resources/sysctl.rb" - dpkg --configure gitlab-ce + if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env + ynh_replace_string --match_string="command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" --replace_string="command \"cat \/etc\/sysctl.conf\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb" + ynh_exec_warn_less dpkg --configure gitlab-ce fi else - dpkg -i $tempdir/$gitlab_filename + ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_print_info "Configuring nginx web server..." +ynh_script_progression --message="Configuring nginx web server..." --time # Create a dedicated nginx config ynh_add_nginx_config client_max_body_size @@ -187,10 +185,10 @@ ynh_add_nginx_config client_max_body_size #================================================= # ADD USER AND CONFIGURE SIGN IN SYSTEM #================================================= -ynh_print_info "Creating an administrator user..." +ynh_script_progression --message="Creating an administrator user..." --time -mailadmin=$(ynh_user_get_info $admin mail) -rdmPass=$(ynh_string_random 30) +mailadmin=$(ynh_user_get_info --username=$admin --key=mail) +rdmPass=$(ynh_string_random --length=30) echo "newuser = User.new({ \"email\"=>'$mailadmin', \"username\"=>'$admin', \"name\"=>'$admin', \"password\"=>'$rdmPass'}) newuser.admin = true @@ -202,7 +200,7 @@ ApplicationSetting.last.update_attributes(password_authentication_enabled_for_we #================================================= # RECONFIGURE TO TAKE INTO ACCOUNT CHANGES #================================================= -ynh_print_info "Reconfigure gitlab..." +ynh_script_progression --message="Reconfigure gitlab..." --time gitlab-ctl reconfigure @@ -217,18 +215,18 @@ yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/applica #================================================= # SETUP SSOWAT #================================================= -ynh_print_info "Configuring SSOwat..." +ynh_script_progression --message="Configuring SSOwat..." --time # Make app public if necessary if [ $is_public -eq 1 ]; then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." --time ynh_systemd_action --action=reload --service_name=nginx @@ -236,4 +234,4 @@ ynh_systemd_action --action=reload --service_name=nginx # END OF SCRIPT #================================================= -ynh_print_info "Installation of $app completed" +ynh_script_progression --message="Installation of $app completed" --time --last diff --git a/scripts/remove b/scripts/remove index 652f398..70579b9 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,15 +12,15 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --time app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get "$app" domain) -port=$(ynh_app_setting_get "$app" web_port) -portUnicorn=$(ynh_app_setting_get "$app" unicorn_port) -final_path=$(ynh_app_setting_get $app final_path) -config_path=$(ynh_app_setting_get $app config_path) +domain=$(ynh_app_setting_get --app="$app" --key=domain) +port=$(ynh_app_setting_get --app="$app" --key=web_port) +portUnicorn=$(ynh_app_setting_get --app="$app" --key=unicorn_port) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +config_path=$(ynh_app_setting_get --app=$app --key=config_path) #================================================= # STANDARD REMOVE @@ -30,28 +30,28 @@ config_path=$(ynh_app_setting_get $app config_path) if yunohost service status "gitlab-runsvdir" >/dev/null 2>&1 then - ynh_print_info "Removing $app service" + ynh_script_progression --message="Removing $app service" --time yunohost service remove "gitlab-runsvdir" fi #================================================= # STOP GITLAB #================================================= -ynh_print_info "Stopping gitlab" +ynh_script_progression --message="Stopping gitlab" --time gitlab-ctl stop #================================================= # REMOVE GITLAB #================================================= -ynh_print_info "Removing Gitlab" +ynh_script_progression --message="Removing Gitlab" --time dpkg --remove gitlab-ce #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_print_info "Removing dependencies" +ynh_script_progression --message="Removing dependencies" --time # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -59,16 +59,16 @@ ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_print_info "Removing app main directory" +ynh_script_progression --message="Removing app main directory" --time # Remove the app directory securely -ynh_secure_remove "$final_path" -ynh_secure_remove "$config_path" +ynh_secure_remove --file="$final_path" +ynh_secure_remove --file="$config_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_print_info "Removing nginx web server configuration" +ynh_script_progression --message="Removing nginx web server configuration" --time # Remove the dedicated nginx config ynh_remove_nginx_config @@ -79,12 +79,12 @@ ynh_remove_nginx_config # These ports are no longer open but were in previous versions if yunohost firewall list | grep -q "\- $port$"; then - ynh_print_info "Closing port $port" + ynh_script_progression --message="Closing port $port" --time ynh_exec_warn_less yunohost firewall disallow TCP $port fi if yunohost firewall list | grep -q "\- $portUnicorn$"; then - ynh_print_info "Closing port $portUnicorn" + ynh_script_progression --message="Closing port $portUnicorn" --time ynh_exec_warn_less yunohost firewall disallow TCP $portUnicorn fi @@ -94,13 +94,13 @@ fi # REMOVE GITLAB FILES #================================================= -ynh_secure_remove "/var/opt/$app" +ynh_secure_remove --file="/var/opt/$app" # Remove the log files -ynh_secure_remove "/var/log/$app" +ynh_secure_remove --file="/var/log/$app" #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Removal of $app completed" +ynh_script_progression --message="Removal of $app completed" --time --last diff --git a/scripts/restore b/scripts/restore index 42cd9f8..9a9cc74 100644 --- a/scripts/restore +++ b/scripts/restore @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_secure_remove "$tempdir" 2>&1 + ynh_exec_warn_less ynh_secure_remove --file="$tempdir" } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -23,27 +23,27 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading settings..." +ynh_script_progression --message="Loading settings..." --time app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) -config_path=$(ynh_app_setting_get $app config_path) -port=$(ynh_app_setting_get "$app" web_port) -portUnicorn=$(ynh_app_setting_get "$app" unicorn_port) -architecture=$(ynh_app_setting_get "$app" architecture) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +config_path=$(ynh_app_setting_get --app=$app --key=config_path) +port=$(ynh_app_setting_get --app="$app" --key=web_port) +portUnicorn=$(ynh_app_setting_get --app="$app" --key=unicorn_port) +architecture=$(ynh_app_setting_get --app="$app" --key=architecture) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_print_info "Validating restoration parameters..." +ynh_script_progression --message="Validating restoration parameters..." --time -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " +|| ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -51,12 +51,12 @@ test ! -d $final_path \ # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_print_info "Reinstalling dependencies..." +ynh_script_progression --message="Reinstalling dependencies..." --time # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies @@ -64,28 +64,28 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE CONF FILES #================================================= -ynh_print_info "Restoring configuration files of Gitlab..." +ynh_script_progression --message="Restoring configuration files of Gitlab..." --time -ynh_restore_file "$config_path/gitlab-secrets.json" -ynh_restore_file "$config_path/gitlab.rb" -ynh_restore_file "$config_path/gitlab-persistent.rb" +ynh_restore_file --origin_path="$config_path/gitlab-secrets.json" +ynh_restore_file --origin_path="$config_path/gitlab.rb" +ynh_restore_file --origin_path="$config_path/gitlab-persistent.rb" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_print_info "Reinstalling gitlab..." +ynh_script_progression --message="Reinstalling gitlab..." --time update_src_version() { source ../settings/scripts/upgrade.d/upgrade.last.sh mkdir -p ../conf/ cp ../settings/conf/$architecture.src.default ../conf/$architecture.src - ynh_replace_string "__VERSION__" "$gitlab_version" "../conf/$architecture.src" - ynh_replace_string "__SOURCE_FILENAME__" "$gitlab_filename" "../conf/$architecture.src" + ynh_replace_string --match_string="__VERSION__" --replace_string="$gitlab_version" --target_file="../conf/$architecture.src" + ynh_replace_string --match_string="__SOURCE_FILENAME__" --replace_string="$gitlab_filename" --target_file="../conf/$architecture.src" if [ $architecture = "x86-64" ]; then - ynh_replace_string "__SHA256_SUM__" "$gitlab_x86_64_source_sha256" "../conf/$architecture.src" + ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_x86_64_source_sha256" --target_file="../conf/$architecture.src" elif [ $architecture = "arm" ]; then - ynh_replace_string "__SHA256_SUM__" "$gitlab_arm_source_sha256" "../conf/$architecture.src" + ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_arm_source_sha256" --target_file="../conf/$architecture.src" fi } @@ -93,15 +93,15 @@ update_src_version tempdir="$(mktemp -d)" -ynh_setup_source $tempdir $architecture +ynh_setup_source --dest_dir=$tempdir --source_id=$architecture if IS_PACKAGE_CHECK; then - if ! dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env - ynh_replace_string "command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" "command \"cat \/etc\/sysctl.conf\"" "$final_path/embedded/cookbooks/package/resources/sysctl.rb" - dpkg --configure gitlab-ce + if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env + ynh_replace_string --match_string="command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" --replace_string="command \"cat \/etc\/sysctl.conf\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb" + ynh_exec_warn_less dpkg --configure gitlab-ce fi else - dpkg -i $tempdir/$gitlab_filename + ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename fi #================================================= @@ -109,9 +109,9 @@ fi #================================================= # RESTORE GITLAB DATABASE #================================================= -ynh_print_info "Restoring Gitlab..." +ynh_script_progression --message="Restoring Gitlab..." --time -ynh_restore_file "/var/opt/$app/backups/last_gitlab_backup.tar" +ynh_restore_file --origin_path="/var/opt/$app/backups/last_gitlab_backup.tar" last_backup="last" @@ -134,14 +134,14 @@ yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/applica #================================================= # WAITING GITLAB #================================================= -ynh_print_info "Waiting for gitlab..." +ynh_script_progression --message="Waiting for gitlab..." --time ynh_systemd_action --action=restart --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --line_match="adopted" --timeout=3600 #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." --time ynh_systemd_action --action=reload --service_name=nginx @@ -149,4 +149,4 @@ ynh_systemd_action --action=reload --service_name=nginx # END OF SCRIPT #================================================= -ynh_print_info "Restoration completed for $app" +ynh_script_progression --message="Restoration completed for $app" --time --last diff --git a/scripts/upgrade b/scripts/upgrade index 2899d47..f72df77 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -19,19 +19,19 @@ source ./_common.sh app=$YNH_APP_INSTANCE_NAME # Retrieve app settings -domain=$(ynh_app_setting_get "$app" domain) -path_url=$(ynh_app_setting_get "$app" path_url) -admin=$(ynh_app_setting_get "$app" admin) -is_public=$(ynh_app_setting_get "$app" is_public) -final_path=$(ynh_app_setting_get $app final_path) -config_path=$(ynh_app_setting_get $app config_path) -port=$(ynh_app_setting_get "$app" web_port) -portUnicorn=$(ynh_app_setting_get "$app" unicorn_port) -portSidekiq=$(ynh_app_setting_get "$app" sidekiq_port) -architecture=$(ynh_app_setting_get "$app" architecture) -unicorn_worker_processes=$(ynh_app_setting_get "$app" unicorn_worker_processes) -client_max_body_size=$(ynh_app_setting_get "$app" client_max_body_size) -overwrite_nginx=$(ynh_app_setting_get "$app" overwrite_nginx) +domain=$(ynh_app_setting_get --app="$app" --key=domain) +path_url=$(ynh_app_setting_get --app="$app" --key=path_url) +admin=$(ynh_app_setting_get --app="$app" --key=admin) +is_public=$(ynh_app_setting_get --app="$app" --key=is_public) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +config_path=$(ynh_app_setting_get --app=$app --key=config_path) +port=$(ynh_app_setting_get --app="$app" --key=web_port) +portUnicorn=$(ynh_app_setting_get --app="$app" --key=unicorn_port) +portSidekiq=$(ynh_app_setting_get --app="$app" --key=sidekiq_port) +architecture=$(ynh_app_setting_get --app="$app" --key=architecture) +unicorn_worker_processes=$(ynh_app_setting_get --app="$app" --key=unicorn_worker_processes) +client_max_body_size=$(ynh_app_setting_get --app="$app" --key=client_max_body_size) +overwrite_nginx=$(ynh_app_setting_get --app="$app" --key=overwrite_nginx) #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -39,23 +39,23 @@ overwrite_nginx=$(ynh_app_setting_get "$app" overwrite_nginx) # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 + ynh_app_setting_set --app=$app --key=is_public --value=1 is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 + ynh_app_setting_set --app=$app --key=is_public --value=0 is_public=0 fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then final_path=/opt/$app - ynh_app_setting_set $app final_path $final_path + ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi # If config_path doesn't exist, create it if [ -z "$config_path" ]; then config_path=/etc/$app - ynh_app_setting_set $app config_path $config_path + ynh_app_setting_set --app=$app --key=config_path --value=$config_path fi if [ -z "$unicorn_worker_processes" ]; then @@ -70,13 +70,13 @@ if [ -z "$unicorn_worker_processes" ]; then # 2 worker processes unicorn_worker_processes=2 fi - ynh_app_setting_set $app unicorn_worker_processes $unicorn_worker_processes + ynh_app_setting_set --app=$app --key=unicorn_worker_processes --value=$unicorn_worker_processes fi if [ -z "$portSidekiq" ]; then portSidekiq=$(ynh_find_port $(($portUnicorn + 1))) - ynh_app_setting_set $app sidekiq_port $portSidekiq + ynh_app_setting_set --app=$app --key=sidekiq_port --value=$portSidekiq fi # If architecture doesn't exist, create it @@ -89,10 +89,10 @@ if [ -z "$architecture" ]; then elif [ -n "$(uname -m | grep arm)" ]; then architecture="arm" else - ynh_die "Unable to detect your achitecture, please open a bug describing \ + ynh_die --message="Unable to detect your achitecture, please open a bug describing \ your hardware and the result of the command \"uname -m\"." 1 fi - ynh_app_setting_set $app architecture $architecture + ynh_app_setting_set --app=$app --key=architecture --value=$architecture fi # If client_max_body_size doesn't exist, create it @@ -103,7 +103,7 @@ fi # If overwrite_nginx doesn't exist, create it if [ -z "$overwrite_nginx" ]; then overwrite_nginx=1 - ynh_app_setting_set $app overwrite_nginx $overwrite_nginx + ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx fi # If domain doesn't exist, retrieve it @@ -112,42 +112,42 @@ if [ -z "$domain" ]; then if [ ${domain: -1} == "'" ]; then # if the last char of $domain is ' remove it domain=${domain:0:-1} fi - ynh_app_setting_set $app domain $domain + ynh_app_setting_set --app=$app --key=domain --value=$domain fi # If path_url doesn't exist, retrieve it if [ -z "$path_url" ]; then path_url=$(grep "location" "/etc/nginx/conf.d/${domain}.d/gitlab.conf" | cut -d' ' -f2) path_url=$(ynh_normalize_url_path $path_url) - ynh_app_setting_set $app path_url path_url + ynh_app_setting_set --app=$app --key=path_url --value=path_url fi # If port doesn't exist, retrieve it if [ -z "$port" ]; then port=$(grep -F "nginx['listen_port']" "/etc/gitlab/gitlab.rb" | cut -d' ' -f3) - ynh_app_setting_set $app web_port $port + ynh_app_setting_set --app=$app --key=web_port --value=$port fi # If port doesn't exist, retrieve it if [ -z "$portUnicorn" ]; then portUnicorn=$(grep -F "unicorn['port']" "/etc/gitlab/gitlab.rb" | cut -d' ' -f3) - ynh_app_setting_set $app unicorn_port $portUnicorn + ynh_app_setting_set --app=$app --key=unicorn_port --value=$portUnicorn fi # if this source file exist, remove it if [ -e "/etc/apt/sources.list.d/gitlab-ce.list" ]; then - ynh_secure_remove "/etc/apt/sources.list.d/gitlab-ce.list" + ynh_secure_remove --file="/etc/apt/sources.list.d/gitlab-ce.list" fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_print_info "Backing up the app before upgrading (may take a while)..." +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - ynh_secure_remove "$tempdir" 2>&1 + ynh_exec_warn_less ynh_secure_remove --file="$tempdir" ynh_clean_check_starting @@ -169,7 +169,7 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_print_info "Installing dependencies..." +ynh_script_progression --message="Installing dependencies..." --time ynh_install_app_dependencies $pkg_dependencies @@ -177,24 +177,24 @@ ynh_install_app_dependencies $pkg_dependencies # PRECONFIGURE GITLAB #================================================= -ynh_print_info "Preconfigure gitlab..." +ynh_script_progression --message="Preconfigure gitlab..." --time -ynh_backup_if_checksum_is_different "$config_path/gitlab.rb" +ynh_backup_if_checksum_is_different --file="$config_path/gitlab.rb" mkdir -p $config_path cp -f ../conf/gitlab.rb "$config_path/gitlab.rb" ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+") -ynh_replace_string "__GENERATED_EXTERNAL_URL__" "https://$domain${path_url%/}" "$config_path/gitlab.rb" -ynh_replace_string "__PORT__" "$port" "$config_path/gitlab.rb" -ynh_replace_string "__UNICORN_PORT__" "$portUnicorn" "$config_path/gitlab.rb" -ynh_replace_string "__UNICORN_WORKER_PROCESSES__" "$unicorn_worker_processes" "$config_path/gitlab.rb" -ynh_replace_string "__CLIENT_MAX_BODY_SIZE__" "$client_max_body_size" "$config_path/gitlab.rb" -ynh_replace_string "__SSH_PORT__" "$ssh_port" "$config_path/gitlab.rb" -ynh_replace_string "__SIDEKIQ_PORT__" "$portSidekiq" "$config_path/gitlab.rb" +ynh_replace_string --match_string="__GENERATED_EXTERNAL_URL__" --replace_string="https://$domain${path_url%/}" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__UNICORN_PORT__" --replace_string="$portUnicorn" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__UNICORN_WORKER_PROCESSES__" --replace_string="$unicorn_worker_processes" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__CLIENT_MAX_BODY_SIZE__" --replace_string="$client_max_body_size" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__SSH_PORT__" --replace_string="$ssh_port" --target_file="$config_path/gitlab.rb" +ynh_replace_string --match_string="__SIDEKIQ_PORT__" --replace_string="$portSidekiq" --target_file="$config_path/gitlab.rb" -ynh_store_file_checksum "$config_path/gitlab.rb" +ynh_store_file_checksum --file="$config_path/gitlab.rb" touch "$config_path/gitlab-persistent.rb" chown admin: "$config_path/gitlab-persistent.rb" @@ -202,18 +202,18 @@ chown admin: "$config_path/gitlab-persistent.rb" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_print_info "Setting up source files..." +ynh_script_progression --message="Setting up source files..." --time update_src_version() { source ./upgrade.d/upgrade.last.sh cp ../conf/$architecture.src.default ../conf/$architecture.src - ynh_replace_string "__VERSION__" "$gitlab_version" "../conf/$architecture.src" - ynh_replace_string "__SOURCE_FILENAME__" "$gitlab_filename" "../conf/$architecture.src" + ynh_replace_string --match_string="__VERSION__" --replace_string="$gitlab_version" --target_file="../conf/$architecture.src" + ynh_replace_string --match_string="__SOURCE_FILENAME__" --replace_string="$gitlab_filename" --target_file="../conf/$architecture.src" if [ $architecture = "x86-64" ]; then - ynh_replace_string "__SHA256_SUM__" "$gitlab_x86_64_source_sha256" "../conf/$architecture.src" + ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_x86_64_source_sha256" --target_file="../conf/$architecture.src" elif [ $architecture = "arm" ]; then - ynh_replace_string "__SHA256_SUM__" "$gitlab_arm_source_sha256" "../conf/$architecture.src" + ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_arm_source_sha256" --target_file="../conf/$architecture.src" fi } @@ -221,15 +221,15 @@ update_src_version tempdir="$(mktemp -d)" -ynh_setup_source $tempdir $architecture +ynh_setup_source --dest_dir=$tempdir --source_id=$architecture if IS_PACKAGE_CHECK; then - if ! dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env - ynh_replace_string "command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" "command \"cat \/etc\/sysctl.conf\"" "$final_path/embedded/cookbooks/package/resources/sysctl.rb" - dpkg --configure gitlab-ce + if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env + ynh_replace_string --match_string="command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" --replace_string="command \"cat \/etc\/sysctl.conf\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb" + ynh_exec_warn_less dpkg --configure gitlab-ce fi else - dpkg -i $tempdir/$gitlab_filename + ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename fi #================================================= @@ -239,7 +239,7 @@ fi # Overwrite the nginx configuration only if it's allowed if [ $overwrite_nginx -eq 1 ] then - ynh_print_info "Configuring nginx web server..." + ynh_script_progression --message="Configuring nginx web server..." --time # Create a dedicated nginx config ynh_add_nginx_config client_max_body_size fi @@ -259,13 +259,13 @@ yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/applica # If app is public, add url to SSOWat conf as skipped_uris if [ $is_public -eq 1 ]; then # See install script - ynh_app_setting_set "$app" unprotected_uris "/" + ynh_app_setting_set --app="$app" --key=unprotected_uris --value="/" fi #================================================= # WAITING GITLAB #================================================= -ynh_print_info "Waiting for gitlab..." +ynh_script_progression --message="Waiting for gitlab..." --time # Action status to just wait the service ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --line_match="adopted" --timeout=3600 @@ -273,7 +273,7 @@ ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path=" #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." --time ynh_systemd_action --action=reload --service_name=nginx @@ -281,5 +281,4 @@ ynh_systemd_action --action=reload --service_name=nginx # END OF SCRIPT #================================================= -ynh_print_info "Upgrade of $app completed" - +ynh_script_progression --message="Upgrade of $app completed" --time --last From e9c5eee664fa3dd9a5d1b7190e295bb014ddb89c Mon Sep 17 00:00:00 2001 From: Kay0u Date: Thu, 9 May 2019 09:03:19 +0200 Subject: [PATCH 08/16] Update progression --- scripts/actions/public_private | 8 ++++---- scripts/actions/web_account | 4 ++-- scripts/backup | 10 +++++----- scripts/change_url | 16 ++++++++-------- scripts/install | 24 ++++++++++++------------ scripts/remove | 20 ++++++++++---------- scripts/restore | 18 +++++++++--------- scripts/upgrade | 16 ++++++++-------- 8 files changed, 58 insertions(+), 58 deletions(-) diff --git a/scripts/actions/public_private b/scripts/actions/public_private index 9559106..5aa6f5d 100644 --- a/scripts/actions/public_private +++ b/scripts/actions/public_private @@ -43,7 +43,7 @@ if [ $is_public -eq 0 ]; then else public_private="public" fi -ynh_script_progression --message=--message="Moving the application to $public_private..." --time +ynh_script_progression --message=--message="Moving the application to $public_private..." --weight=1 # Make app public if necessary if [ $is_public -eq 0 ]; then @@ -53,7 +53,7 @@ else ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi -ynh_script_progression --message=--message="Reconfiguring SSOwat..." --time +ynh_script_progression --message=--message="Reconfiguring SSOwat..." --weight=1 # Regen ssowat configuration yunohost app ssowatconf @@ -63,7 +63,7 @@ ynh_app_setting_set --app=$app --key=is_public --value=$is_public #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message=--message="Reloading nginx web server..." --time +ynh_script_progression --message=--message="Reloading nginx web server..." --weight=1 ynh_systemd_action --action=reload --service_name=nginx @@ -71,4 +71,4 @@ ynh_systemd_action --action=reload --service_name=nginx # END OF SCRIPT #================================================= -ynh_print_info --message="Execution completed" \ No newline at end of file +ynh_script_progression --message="Execution completed" --last \ No newline at end of file diff --git a/scripts/actions/web_account b/scripts/actions/web_account index 629710d..4f6111a 100644 --- a/scripts/actions/web_account +++ b/scripts/actions/web_account @@ -43,7 +43,7 @@ if [ $use_web_account -eq 0 ]; then else web_account="Disable" fi -ynh_script_progression --message=--message="$web_account web user creation..." --time +ynh_script_progression --message=--message="$web_account web user creation..." --weight=13 echo "ApplicationSetting.last.update_attributes(password_authentication_enabled_for_web: $use_web_account, signup_enabled: $use_web_account)" | gitlab-rails console @@ -54,4 +54,4 @@ ynh_app_setting_set --app=$app --key=use_web_account --value=$use_web_account # END OF SCRIPT #================================================= -ynh_print_info --message="Execution completed" \ No newline at end of file +ynh_script_progression --message="Execution completed" --last \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index f38d75a..b205998 100644 --- a/scripts/backup +++ b/scripts/backup @@ -24,7 +24,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -37,14 +37,14 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." --time +ynh_script_progression --message="Backing up nginx web server configuration..." --weight=1 ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP GITLAB DATABASE #================================================= -ynh_script_progression --message="Backuping of Gitlab..." --time +ynh_script_progression --message="Backuping of Gitlab..." --weight=9 # Use gitlab-rake to backup gitlab-rake gitlab:backup:create > backup.log @@ -58,7 +58,7 @@ ynh_backup --src_path="/var/opt/$app/backups/last_gitlab_backup.tar" #================================================= # BACKUP CONF FILES #================================================= -ynh_script_progression --message="Backuping configuration files of Gitlab..." --time +ynh_script_progression --message="Backuping configuration files of Gitlab..." --weight=1 ynh_backup --src_path="$config_path/gitlab-secrets.json" ynh_backup --src_path="$config_path/gitlab.rb" @@ -68,4 +68,4 @@ ynh_backup --src_path="$config_path/gitlab-persistent.rb" # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last diff --git a/scripts/change_url b/scripts/change_url index c16fe04..690d226 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,7 +24,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time +ynh_script_progression --message="Loading installation settings..." --weight=1 # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) @@ -54,12 +54,12 @@ fi #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating nginx web server configuration..." --time +ynh_script_progression --message="Updating nginx web server configuration..." --weight=1 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf if [ $change_path -eq 1 ]; then - ynh_script_progression --message="Changing path..." --time + ynh_script_progression --message="Changing path..." --weight=4 #doc in: https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab @@ -77,7 +77,7 @@ fi # Change the domain for nginx if [ $change_domain -eq 1 ]; then - ynh_script_progression --message="Changing domain..." --time + ynh_script_progression --message="Changing domain..." --weight=4 # Delete file checksum for the old conf file location ynh_delete_file_checksum --file="$nginx_conf_path" @@ -91,7 +91,7 @@ fi #================================================= # CONFIGURE GITLAB #================================================= -ynh_script_progression --message="Configure gitlab..." --time +ynh_script_progression --message="Configure gitlab..." --weight=28 ynh_backup_if_checksum_is_different --file="$config_path/gitlab.rb" @@ -127,7 +127,7 @@ fi #================================================= # WAITING GITLAB #================================================= -ynh_script_progression --message="Waiting for gitlab..." --time +ynh_script_progression --message="Waiting for gitlab..." --weight=15 # Action status to just wait the service ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --line_match="adopted" --timeout=3600 @@ -137,7 +137,7 @@ ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path=" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time +ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --action=reload --service_name=nginx @@ -145,4 +145,4 @@ ynh_systemd_action --action=reload --service_name=nginx # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --time --last +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index e392906..96fe7df 100644 --- a/scripts/install +++ b/scripts/install @@ -36,7 +36,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_script_progression --message="Validating installation parameters..." --time +ynh_script_progression --message="Validating installation parameters..." --weight=1 config_path=/etc/$app final_path=/opt/$app @@ -75,7 +75,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --time +ynh_script_progression --message="Storing installation settings..." --weight=2 ynh_app_setting_set --app=$app --key=admin --value=$admin ynh_app_setting_set --app=$app --key=path_url --value=$path_url @@ -94,7 +94,7 @@ ynh_app_setting_set --app=$app --key=overwrite_nginx --value="1" #================================================= # FIND A PORT #================================================= -ynh_script_progression --message="Find internal port..." --time +ynh_script_progression --message="Find internal port..." --weight=1 # Find free ports port=$(ynh_find_port --port=8080) @@ -108,14 +108,14 @@ ynh_app_setting_set --app=$app --key=sidekiq_port --value=$portSidekiq #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --time +ynh_script_progression --message="Installing dependencies..." --weight=5 ynh_install_app_dependencies $pkg_dependencies #================================================= # PRECONFIGURE GITLAB #================================================= -ynh_script_progression --message="Preconfigure gitlab..." --time +ynh_script_progression --message="Preconfigure gitlab..." --weight=1 mkdir -p $config_path @@ -142,7 +142,7 @@ ynh_store_file_checksum --file="$config_path/gitlab.rb" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --time +ynh_script_progression --message="Setting up source files..." --weight=853 update_src_version() { source ./upgrade.d/upgrade.last.sh @@ -175,7 +175,7 @@ fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx web server..." --time +ynh_script_progression --message="Configuring nginx web server..." --weight=2 # Create a dedicated nginx config ynh_add_nginx_config client_max_body_size @@ -185,7 +185,7 @@ ynh_add_nginx_config client_max_body_size #================================================= # ADD USER AND CONFIGURE SIGN IN SYSTEM #================================================= -ynh_script_progression --message="Creating an administrator user..." --time +ynh_script_progression --message="Creating an administrator user..." --weight=13 mailadmin=$(ynh_user_get_info --username=$admin --key=mail) rdmPass=$(ynh_string_random --length=30) @@ -200,7 +200,7 @@ ApplicationSetting.last.update_attributes(password_authentication_enabled_for_we #================================================= # RECONFIGURE TO TAKE INTO ACCOUNT CHANGES #================================================= -ynh_script_progression --message="Reconfigure gitlab..." --time +ynh_script_progression --message="Reconfigure gitlab..." --weight=13 gitlab-ctl reconfigure @@ -215,7 +215,7 @@ yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/applica #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." --time +ynh_script_progression --message="Configuring SSOwat..." --weight=1 # Make app public if necessary if [ $is_public -eq 1 ]; then @@ -226,7 +226,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time +ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --action=reload --service_name=nginx @@ -234,4 +234,4 @@ ynh_systemd_action --action=reload --service_name=nginx # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --time --last +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index 70579b9..353e964 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time +ynh_script_progression --message="Loading installation settings..." --weight=2 app=$YNH_APP_INSTANCE_NAME @@ -30,28 +30,28 @@ config_path=$(ynh_app_setting_get --app=$app --key=config_path) if yunohost service status "gitlab-runsvdir" >/dev/null 2>&1 then - ynh_script_progression --message="Removing $app service" --time + ynh_script_progression --message="Removing $app service" --weight=1 yunohost service remove "gitlab-runsvdir" fi #================================================= # STOP GITLAB #================================================= -ynh_script_progression --message="Stopping gitlab" --time +ynh_script_progression --message="Stopping gitlab" --weight=8 gitlab-ctl stop #================================================= # REMOVE GITLAB #================================================= -ynh_script_progression --message="Removing Gitlab" --time +ynh_script_progression --message="Removing Gitlab" --weight=4 dpkg --remove gitlab-ce #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies" --time +ynh_script_progression --message="Removing dependencies" --weight=3 # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -59,7 +59,7 @@ ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory" --time +ynh_script_progression --message="Removing app main directory" --weight=1 # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -68,7 +68,7 @@ ynh_secure_remove --file="$config_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing nginx web server configuration" --time +ynh_script_progression --message="Removing nginx web server configuration" --weight=1 # Remove the dedicated nginx config ynh_remove_nginx_config @@ -79,12 +79,12 @@ ynh_remove_nginx_config # These ports are no longer open but were in previous versions if yunohost firewall list | grep -q "\- $port$"; then - ynh_script_progression --message="Closing port $port" --time + ynh_script_progression --message="Closing port $port" --weight=1 ynh_exec_warn_less yunohost firewall disallow TCP $port fi if yunohost firewall list | grep -q "\- $portUnicorn$"; then - ynh_script_progression --message="Closing port $portUnicorn" --time + ynh_script_progression --message="Closing port $portUnicorn" --weight=1 ynh_exec_warn_less yunohost firewall disallow TCP $portUnicorn fi @@ -103,4 +103,4 @@ ynh_secure_remove --file="/var/log/$app" # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --time --last +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 9a9cc74..75e5dc5 100644 --- a/scripts/restore +++ b/scripts/restore @@ -23,7 +23,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --time +ynh_script_progression --message="Loading settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -38,7 +38,7 @@ architecture=$(ynh_app_setting_get --app="$app" --key=architecture) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." --time +ynh_script_progression --message="Validating restoration parameters..." --weight=1 ynh_webpath_available --domain=$domain --path_url=$path_url \ || ynh_die --message="Path not available: ${domain}${path_url}" @@ -56,7 +56,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --time +ynh_script_progression --message="Reinstalling dependencies..." --weight=5 # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies @@ -64,7 +64,7 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE CONF FILES #================================================= -ynh_script_progression --message="Restoring configuration files of Gitlab..." --time +ynh_script_progression --message="Restoring configuration files of Gitlab..." --weight=1 ynh_restore_file --origin_path="$config_path/gitlab-secrets.json" ynh_restore_file --origin_path="$config_path/gitlab.rb" @@ -73,7 +73,7 @@ ynh_restore_file --origin_path="$config_path/gitlab-persistent.rb" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Reinstalling gitlab..." --time +ynh_script_progression --message="Reinstalling gitlab..." --weight=853 update_src_version() { source ../settings/scripts/upgrade.d/upgrade.last.sh @@ -109,7 +109,7 @@ fi #================================================= # RESTORE GITLAB DATABASE #================================================= -ynh_script_progression --message="Restoring Gitlab..." --time +ynh_script_progression --message="Restoring Gitlab..." --weight=55 ynh_restore_file --origin_path="/var/opt/$app/backups/last_gitlab_backup.tar" @@ -134,14 +134,14 @@ yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/applica #================================================= # WAITING GITLAB #================================================= -ynh_script_progression --message="Waiting for gitlab..." --time +ynh_script_progression --message="Waiting for gitlab..." --weight=14 ynh_systemd_action --action=restart --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --line_match="adopted" --timeout=3600 #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time +ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --action=reload --service_name=nginx @@ -149,4 +149,4 @@ ynh_systemd_action --action=reload --service_name=nginx # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --time --last +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index f72df77..9447e1c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -142,7 +142,7 @@ fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=10 # Backup the current version of the app ynh_backup_before_upgrade @@ -169,7 +169,7 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --time +ynh_script_progression --message="Installing dependencies..." --weight=5 ynh_install_app_dependencies $pkg_dependencies @@ -177,7 +177,7 @@ ynh_install_app_dependencies $pkg_dependencies # PRECONFIGURE GITLAB #================================================= -ynh_script_progression --message="Preconfigure gitlab..." --time +ynh_script_progression --message="Preconfigure gitlab..." --weight=1 ynh_backup_if_checksum_is_different --file="$config_path/gitlab.rb" @@ -202,7 +202,7 @@ chown admin: "$config_path/gitlab-persistent.rb" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --time +ynh_script_progression --message="Setting up source files..." --weight=690 update_src_version() { source ./upgrade.d/upgrade.last.sh @@ -239,7 +239,7 @@ fi # Overwrite the nginx configuration only if it's allowed if [ $overwrite_nginx -eq 1 ] then - ynh_script_progression --message="Configuring nginx web server..." --time + ynh_script_progression --message="Configuring nginx web server..." --weight=2 # Create a dedicated nginx config ynh_add_nginx_config client_max_body_size fi @@ -265,7 +265,7 @@ fi #================================================= # WAITING GITLAB #================================================= -ynh_script_progression --message="Waiting for gitlab..." --time +ynh_script_progression --message="Waiting for gitlab..." --weight=15 # Action status to just wait the service ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --line_match="adopted" --timeout=3600 @@ -273,7 +273,7 @@ ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path=" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time +ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --action=reload --service_name=nginx @@ -281,4 +281,4 @@ ynh_systemd_action --action=reload --service_name=nginx # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --time --last +ynh_script_progression --message="Upgrade of $app completed"--last From 7e2ba4785dc445ff7a16cf373f91de8e1aa5647c Mon Sep 17 00:00:00 2001 From: kay0u Date: Thu, 9 May 2019 10:41:49 +0200 Subject: [PATCH 09/16] use ynh_check_app_version_changed --- scripts/upgrade | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 9447e1c..682a94c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -33,6 +33,12 @@ unicorn_worker_processes=$(ynh_app_setting_get --app="$app" --key=unicorn_worker client_max_body_size=$(ynh_app_setting_get --app="$app" --key=client_max_body_size) overwrite_nginx=$(ynh_app_setting_get --app="$app" --key=overwrite_nginx) +#================================================= +# CHECK VERSION +#================================================= + +upgrade_type=$(ynh_check_app_version_changed) + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -202,7 +208,6 @@ chown admin: "$config_path/gitlab-persistent.rb" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=690 update_src_version() { source ./upgrade.d/upgrade.last.sh @@ -217,19 +222,26 @@ update_src_version() { fi } -update_src_version +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Setting up source files..." --weight=690 -tempdir="$(mktemp -d)" + update_src_version -ynh_setup_source --dest_dir=$tempdir --source_id=$architecture + tempdir="$(mktemp -d)" -if IS_PACKAGE_CHECK; then - if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env - ynh_replace_string --match_string="command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" --replace_string="command \"cat \/etc\/sysctl.conf\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb" - ynh_exec_warn_less dpkg --configure gitlab-ce + ynh_setup_source --dest_dir=$tempdir --source_id=$architecture + + if IS_PACKAGE_CHECK; then + if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env + ynh_replace_string --match_string="command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" --replace_string="command \"cat \/etc\/sysctl.conf\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb" + ynh_exec_warn_less dpkg --configure gitlab-ce + fi + else + ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename fi -else - ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename + + ynh_exec_warn_less ynh_secure_remove --file="$tempdir" fi #================================================= From ee160ea53422566eb17b86b3700a7b5ea95f0bde Mon Sep 17 00:00:00 2001 From: kay0u Date: Thu, 9 May 2019 10:44:22 +0200 Subject: [PATCH 10/16] prevent swaping on SD card --- scripts/_common.sh | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index bac71f7..baa3636 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -36,20 +36,6 @@ bool_to_true_false () { # EXPERIMENTAL HELPERS #================================================= -# Check if the device of the main mountpoint "/" is an SD card -# -# return 1 if it's an SD card, else 0 -_ynh_is_main_device_is_sd_card () { - local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) - - if echo $main_device | grep --quiet "mmc" && [ $(cat /sys/block/$main_device/queue/rotational) -eq 0 ] - then - return 1 - else - return 0 - fi -} - # Add swap # # usage: ynh_add_swap --size=SWAP in Mb @@ -70,7 +56,7 @@ ynh_add_swap () { SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} # Swap on SD card only if it's is specified - if [ _ynh_is_main_device_is_sd_card ] && [ "$SD_CARD_CAN_SWAP" == "0" ] + if ynh_is_main_device_is_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] then return fi @@ -122,6 +108,22 @@ ynh_del_swap () { fi } +# Check if the device of the main mountpoint "/" is an SD card +# +# [internal] +# +# return 0 if it's an SD card, else 1 +ynh_is_main_device_is_sd_card () { + local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) + + if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] + then + return 0 + else + return 1 + fi +} + # Check the amount of available RAM # # usage: ynh_check_ram [--required=RAM required in Mb] [--no_swap|--only_swap] [--free_ram] From 5b43c7c13a52382f6945013943903cc09a2e6510 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Fri, 10 May 2019 23:32:45 +0200 Subject: [PATCH 11/16] Update experimental helpers --- scripts/_common.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index baa3636..cfe8cdb 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -56,8 +56,9 @@ ynh_add_swap () { SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} # Swap on SD card only if it's is specified - if ynh_is_main_device_is_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] + if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] then + ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'" return fi @@ -113,7 +114,7 @@ ynh_del_swap () { # [internal] # # return 0 if it's an SD card, else 1 -ynh_is_main_device_is_sd_card () { +ynh_is_main_device_a_sd_card () { local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] From c3e6a14d34dd38f93508b97648c6534a832c8bea Mon Sep 17 00:00:00 2001 From: Kay0u Date: Sat, 11 May 2019 01:23:40 +0200 Subject: [PATCH 12/16] Upstream app repository --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 16e4267..e906b49 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Yes with LDAP support. * Report a bug: https://github.com/YunoHost-Apps/gitlab_ynh/issues * App website: https://gitlab.com + * Upstream app repository: https://gitlab.com/gitlab-org/omnibus-gitlab - https://gitlab.com/gitlab-org/gitlab-ce * YunoHost website: https://yunohost.org/ --- From 38cd19c3d4f5e1308acef0dbde5d386d5c9e78c6 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Sat, 11 May 2019 01:41:46 +0200 Subject: [PATCH 13/16] swap with getops --- scripts/install | 4 ++-- scripts/restore | 5 ++--- scripts/upgrade | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/scripts/install b/scripts/install index f732768..651f4c0 100644 --- a/scripts/install +++ b/scripts/install @@ -131,8 +131,8 @@ if [ $(($total_swap + $swap_needed)) -lt 2048 ]; then swap_needed=$((2048 - $total_swap)) fi -ynh_print_info "Adding $swap_needed to swap..." -ynh_add_swap $swap_needed +ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 +ynh_add_swap --size=$swap_needed #================================================= # PRECONFIGURE GITLAB diff --git a/scripts/restore b/scripts/restore index df17fc7..591c328 100644 --- a/scripts/restore +++ b/scripts/restore @@ -64,7 +64,6 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # ADD SWAP IF NEEDED #================================================= -ynh_print_info "Adding swap..." total_memory=$(ynh_check_ram) total_swap=$(ynh_check_ram --only_swap) @@ -81,8 +80,8 @@ if [ $(($total_swap + $swap_needed)) -lt 2048 ]; then swap_needed=$((2048 - $total_swap)) fi -ynh_print_info "Adding $swap_needed to swap..." -ynh_add_swap $swap_needed +ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 +ynh_add_swap --size=$swap_needed #================================================= # RESTORE CONF FILES diff --git a/scripts/upgrade b/scripts/upgrade index b40f510..90e7165 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -182,7 +182,6 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # ADD SWAP IF NEEDED #================================================= -ynh_print_info "Adding swap..." total_memory=$(ynh_check_ram) total_swap=$(ynh_check_ram --only_swap) @@ -199,8 +198,8 @@ if [ $(($total_swap + $swap_needed)) -lt 2048 ]; then swap_needed=$((2048 - $total_swap)) fi -ynh_print_info "Adding $swap_needed to swap..." -ynh_add_swap $swap_needed +ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 +ynh_add_swap --size=$swap_needed #================================================= # PRECONFIGURE GITLAB From 76869eea76ca837682e452f98cad43e4d5f2bff9 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Sat, 11 May 2019 01:42:05 +0200 Subject: [PATCH 14/16] update weight --- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 651f4c0..c55991e 100644 --- a/scripts/install +++ b/scripts/install @@ -164,7 +164,7 @@ ynh_store_file_checksum --file="$config_path/gitlab.rb" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=853 +ynh_script_progression --message="Setting up source files..." --weight=200 update_src_version() { source ./upgrade.d/upgrade.last.sh diff --git a/scripts/restore b/scripts/restore index 591c328..601e1bb 100644 --- a/scripts/restore +++ b/scripts/restore @@ -95,7 +95,7 @@ ynh_restore_file --origin_path="$config_path/gitlab-persistent.rb" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Reinstalling gitlab..." --weight=853 +ynh_script_progression --message="Reinstalling gitlab..." --weight=200 update_src_version() { source ../settings/scripts/upgrade.d/upgrade.last.sh diff --git a/scripts/upgrade b/scripts/upgrade index 90e7165..5978325 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -246,7 +246,7 @@ update_src_version() { if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Setting up source files..." --weight=690 + ynh_script_progression --message="Setting up source files..." --weight=200 update_src_version From 97b0e23484f013d3478cc77bad73ac2ec2afa52e Mon Sep 17 00:00:00 2001 From: Kay0u Date: Sun, 12 May 2019 00:30:18 +0200 Subject: [PATCH 15/16] Use PACKAGE_CHECK_EXEC variable --- scripts/_common.sh | 8 -------- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index cfe8cdb..f8ec859 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,14 +6,6 @@ pkg_dependencies="openssh-server" -#================================================= -# PACKAGE CHECK BYPASSING... -#================================================= - -IS_PACKAGE_CHECK () { - return $(env | grep -c container=lxc) -} - #================================================= # BOOLEAN CONVERTER #================================================= diff --git a/scripts/install b/scripts/install index c55991e..ba52a59 100644 --- a/scripts/install +++ b/scripts/install @@ -185,7 +185,7 @@ tempdir="$(mktemp -d)" ynh_setup_source --dest_dir=$tempdir --source_id=$architecture -if IS_PACKAGE_CHECK; then +if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env ynh_replace_string --match_string="command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" --replace_string="command \"cat \/etc\/sysctl.conf\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb" ynh_exec_warn_less dpkg --configure gitlab-ce diff --git a/scripts/restore b/scripts/restore index 601e1bb..f370e86 100644 --- a/scripts/restore +++ b/scripts/restore @@ -117,7 +117,7 @@ tempdir="$(mktemp -d)" ynh_setup_source --dest_dir=$tempdir --source_id=$architecture -if IS_PACKAGE_CHECK; then +if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env ynh_replace_string --match_string="command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" --replace_string="command \"cat \/etc\/sysctl.conf\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb" ynh_exec_warn_less dpkg --configure gitlab-ce diff --git a/scripts/upgrade b/scripts/upgrade index 5978325..5312cdf 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -254,7 +254,7 @@ then ynh_setup_source --dest_dir=$tempdir --source_id=$architecture - if IS_PACKAGE_CHECK; then + if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env ynh_replace_string --match_string="command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" --replace_string="command \"cat \/etc\/sysctl.conf\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb" ynh_exec_warn_less dpkg --configure gitlab-ce From 0e1bc68586b3adac09bff26ccd588353414bdb8c Mon Sep 17 00:00:00 2001 From: Kayou Date: Sun, 12 May 2019 13:52:05 +0200 Subject: [PATCH 16/16] Update manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index d932cc7..ba823b2 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "name": "Gitlab", "id": "gitlab", "packaging_format": 1, - "version": "11.10.4~ynh1", + "version": "11.10.4~ynh2", "description": { "en": "GitLab is a Git-repository manager.", "fr": "GitLab est un gestionnaire de dépôts Git."