1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gitlab_ynh.git synced 2024-09-03 18:36:35 +02:00

Just waiting for gitlab

This commit is contained in:
Pierre Bourré 2019-03-19 00:12:44 +01:00
parent 2dc13b7e84
commit 2273a28e55
5 changed files with 27 additions and 49 deletions

View file

@ -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

View file

@ -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
#=================================================

View file

@ -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

View file

@ -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
#=================================================

View file

@ -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