From 2273a28e55dfe03018f67bbaca2915cac64ce935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Bourr=C3=A9?= Date: Tue, 19 Mar 2019 00:12:44 +0100 Subject: [PATCH] Just waiting for gitlab --- scripts/_common.sh | 52 ++++++++++------------------------------------ scripts/change_url | 8 +++++-- scripts/install | 4 ++-- scripts/restore | 8 +++++-- scripts/upgrade | 4 ++-- 5 files changed, 27 insertions(+), 49 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 151c691..b1e0a9d 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -117,13 +117,11 @@ ynh_systemd_action() { # Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started # -# usage: ynh_systemd_action [-a action] [ [-t timeout] ] -# | arg: -a, --action= - Action to perform with systemctl. Default: start +# usage: gitlab_ctl_waiting [ [-t timeout] ] # | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds. -gitlab_ctl_action() { +gitlab_ctl_waiting() { # Declare an array to define the options of this helper. - declare -Ar args_array=( [a]=action= [t]=timeout= ) - local action + declare -Ar args_array=( [t]=timeout= ) local timeout # Manage arguments with getopts @@ -134,54 +132,26 @@ gitlab_ctl_action() { local line_match_error="master failed to start" local log_path="/var/log/gitlab/unicorn/current" - local action=${action:-start} local timeout=${timeout:-300} - ynh_print_info --message="${action^} gitlab" - - gitlab-ctl $action - - # Start to read the log + # Following the starting of the app in its log local templog="$(mktemp)" - # Read the specified log file - tail -F -n1 "$log_path" > "$templog" 2>&1 & - # Get the PID of the tail command + tail -F -n1 "$log_path" >"$templog" & + # get the PID of the tail command local pid_tail=$! + if grep --quiet "${line_match_error}" $templog; then # error, so restart gitlab + gitlab-ctl restart + fi + # Start the timeout and try to find line_match_new or line_match_existing 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_new" "$templog" - then + if grep --quiet "${line_match_new}" "$templog" || grep --quiet "${line_match_existing}" "$templog"; then ynh_print_info --message="Gitlab has correctly started." break fi - if grep --quiet "$line_match_existing" "$templog" - then - ynh_print_info --message="Gitlab has correctly started." - break - fi - if grep --quiet "$line_match_error" "$templog" - then - ynh_print_warn "Error during ${action}ing, reconfiguring and restarting gitlab" - ynh_clean_check_starting - - gitlab-ctl restart - # Force restart unicorn - gitlab-ctl restart unicorn - - # Start to read the log - local templog="$(mktemp)" - # Read the specified log file - tail -F -n1 "$log_path" > "$templog" 2>&1 & - # Get the PID of the tail command - local pid_tail=$! - fi - if [ $i -eq 3 ]; then - echo -n "Please wait, Gitlab is ${action}ing" >&2 - fi if [ $i -ge 3 ]; then echo -n "." >&2 fi diff --git a/scripts/change_url b/scripts/change_url index e6b8846..f2d9189 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -118,13 +118,17 @@ ynh_store_file_checksum "$config_path/gitlab.rb" # RECONFIGURE GITLAB #================================================= -gitlab_ctl_action --action=reconfigure --timeout=3600 +gitlab-ctl reconfigure if [ $change_path -eq 1 ]; then gitlab-ctl restart - gitlab_ctl_action --action="restart unicorn" --timeout=3600 + gitlab-ctl restart unicorn fi +ynh_print_info "Waiting for gitlab..." + +gitlab_ctl_waiting --timeout=3600 + #================================================= # GENERIC FINALISATION #================================================= diff --git a/scripts/install b/scripts/install index 3ac24d4..bd0f76a 100644 --- a/scripts/install +++ b/scripts/install @@ -196,9 +196,9 @@ fi #================================================= # RESTART GITLAB #================================================= -ynh_print_info "Restarting gitlab..." +ynh_print_info "Waiting for gitlab..." -gitlab_ctl_action --action=restart --timeout=3600 +gitlab_ctl_waiting --timeout=3600 #================================================= # RELOAD NGINX diff --git a/scripts/restore b/scripts/restore index a46ca8d..efa442c 100644 --- a/scripts/restore +++ b/scripts/restore @@ -120,10 +120,14 @@ gitlab-ctl stop sidekiq # Use gitlab-rake to backup ynh_exec_warn_less gitlab-rake gitlab:backup:restore force=yes BACKUP=$last_backup -gitlab_ctl_action --action=restart --timeout=3600 - gitlab-rake gitlab:check SANITIZE=true +gitlab-ctl restart + +ynh_print_info "Waiting for gitlab..." + +gitlab_ctl_waiting --timeout=3600 + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f08e96f..c291efa 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -210,9 +210,9 @@ fi #================================================= # RESTART GITLAB #================================================= -ynh_print_info "Restarting gitlab..." +ynh_print_info "Waiting for gitlab..." -gitlab_ctl_action --action=restart --timeout=3600 +gitlab_ctl_waiting --timeout=3600 #================================================= # RELOAD NGINX