diff --git a/scripts/_common.sh b/scripts/_common.sh index b1e0a9d..51f079c 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -113,62 +113,6 @@ ynh_systemd_action() { fi } -# This function is inspired by the ynh_systemd_action function - -# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started -# -# usage: gitlab_ctl_waiting [ [-t timeout] ] -# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds. -gitlab_ctl_waiting() { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [t]=timeout= ) - local timeout - - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - local line_match_new="adopted new unicorn master" - local line_match_existing="adopted existing unicorn master" - local line_match_error="master failed to start" - local log_path="/var/log/gitlab/unicorn/current" - - local timeout=${timeout:-300} - - # Following the starting of the app in its log - local templog="$(mktemp)" - 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 - 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 [ $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="Gitlab didn't fully started before the timeout." - ynh_print_warn --message="Please find here an extract of the end of the log of Gitlab:" - test -e "$log_path" && echo "--" >&2 && tail --lines=$length "$log_path" >&2 - fi - ynh_clean_check_starting -} - # Clean temporary process and file used by ynh_check_starting # (usually used in ynh_clean_setup scripts) # diff --git a/scripts/change_url b/scripts/change_url index f2d9189..aff2950 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -125,9 +125,13 @@ if [ $change_path -eq 1 ]; then gitlab-ctl restart unicorn fi +#================================================= +# WAITING GITLAB +#================================================= ynh_print_info "Waiting for gitlab..." -gitlab_ctl_waiting --timeout=3600 +# Action status to just wait the service +ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --timeout=3600 #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index bd0f76a..e4715ad 100644 --- a/scripts/install +++ b/scripts/install @@ -182,6 +182,12 @@ gitlab-ctl reconfigure #================================================= # GENERIC FINALIZATION +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/application.log /var/log/$app/gitlab-rails/api_json.log /var/log/$app/gitlab-rails/production.log /var/log/$app/gitlab-rails/production_json.log /var/log/$app/gitlab-rails/sidekiq.log /var/log/$app/unicorn/unicorn_stderr.log /var/log/$app/unicorn/current /var/log/$app/alertmanager/current /var/log/$app/gitaly/current /var/log/$app/gitlab-monitor/current /var/log/$app/gitlab-shell/gitlab-shell.log /var/log/$app/gitlab-workhorse/current /var/log/$app/logrotate/current /var/log/$app/nginx/current /var/log/$app/nginx/access.log /var/log/$app/nginx/error.log /var/log/$app/nginx/gitlab_access.log /var/log/$app/nginx/gitlab_error.log /var/log/$app/node-exporter/current /var/log/$app/postgres-exporter/current /var/log/$app/postgresql/current /var/log/$app/prometheus/current /var/log/$app/redis/current /var/log/$app/redis-exporter/current" + #================================================= # SETUP SSOWAT #================================================= @@ -194,11 +200,12 @@ if [ $is_public -eq 1 ]; then fi #================================================= -# RESTART GITLAB +# WAITING GITLAB #================================================= ynh_print_info "Waiting for gitlab..." -gitlab_ctl_waiting --timeout=3600 +# Action status to just wait the service +ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --timeout=3600 #================================================= # RELOAD NGINX diff --git a/scripts/remove b/scripts/remove index 6fea6e4..38eca51 100644 --- a/scripts/remove +++ b/scripts/remove @@ -24,6 +24,16 @@ config_path=$(ynh_app_setting_get $app config_path) #================================================= # STANDARD REMOVE +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= + +if yunohost service status "gitlab-runsvdir" >/dev/null 2>&1 +then + ynh_print_info "Removing $app service" + yunohost service remove "gitlab-runsvdir" +fi + #================================================= # STOP GITLAB #================================================= diff --git a/scripts/restore b/scripts/restore index efa442c..4fc8e06 100644 --- a/scripts/restore +++ b/scripts/restore @@ -122,14 +122,21 @@ ynh_exec_warn_less gitlab-rake gitlab:backup:restore force=yes BACKUP=$last_back gitlab-rake gitlab:check SANITIZE=true -gitlab-ctl restart - -ynh_print_info "Waiting for gitlab..." - -gitlab_ctl_waiting --timeout=3600 - #================================================= # GENERIC FINALIZATION +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/application.log /var/log/$app/gitlab-rails/api_json.log /var/log/$app/gitlab-rails/production.log /var/log/$app/gitlab-rails/production_json.log /var/log/$app/gitlab-rails/sidekiq.log /var/log/$app/unicorn/unicorn_stderr.log /var/log/$app/unicorn/current /var/log/$app/alertmanager/current /var/log/$app/gitaly/current /var/log/$app/gitlab-monitor/current /var/log/$app/gitlab-shell/gitlab-shell.log /var/log/$app/gitlab-workhorse/current /var/log/$app/logrotate/current /var/log/$app/nginx/current /var/log/$app/nginx/access.log /var/log/$app/nginx/error.log /var/log/$app/nginx/gitlab_access.log /var/log/$app/nginx/gitlab_error.log /var/log/$app/node-exporter/current /var/log/$app/postgres-exporter/current /var/log/$app/postgresql/current /var/log/$app/prometheus/current /var/log/$app/redis/current /var/log/$app/redis-exporter/current" + +#================================================= +# WAITING GITLAB +#================================================= +ynh_print_info "Waiting for gitlab..." + +ynh_systemd_action --action=restart --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --timeout=3600 + #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index c291efa..b671097 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -197,22 +197,29 @@ ynh_add_nginx_config #================================================= # GENERIC FINALIZATION +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/application.log /var/log/$app/gitlab-rails/api_json.log /var/log/$app/gitlab-rails/production.log /var/log/$app/gitlab-rails/production_json.log /var/log/$app/gitlab-rails/sidekiq.log /var/log/$app/unicorn/unicorn_stderr.log /var/log/$app/unicorn/current /var/log/$app/alertmanager/current /var/log/$app/gitaly/current /var/log/$app/gitlab-monitor/current /var/log/$app/gitlab-shell/gitlab-shell.log /var/log/$app/gitlab-workhorse/current /var/log/$app/logrotate/current /var/log/$app/nginx/current /var/log/$app/nginx/access.log /var/log/$app/nginx/error.log /var/log/$app/nginx/gitlab_access.log /var/log/$app/nginx/gitlab_error.log /var/log/$app/node-exporter/current /var/log/$app/postgres-exporter/current /var/log/$app/postgresql/current /var/log/$app/prometheus/current /var/log/$app/redis/current /var/log/$app/redis-exporter/current" + #================================================= # SETUP SSOWAT #================================================= # If app is public, add url to SSOWat conf as skipped_uris -if [[ $is_public -eq 1 ]]; then +if [ $is_public -eq 1 ]; then # See install script ynh_app_setting_set "$app" unprotected_uris "/" fi #================================================= -# RESTART GITLAB +# WAITING GITLAB #================================================= ynh_print_info "Waiting for gitlab..." -gitlab_ctl_waiting --timeout=3600 +# Action status to just wait the service +ynh_systemd_action --action=status --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --timeout=3600 #================================================= # RELOAD NGINX