#!/bin/bash source _common.sh source /usr/share/yunohost/helpers #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= if [ -n $(ynh_app_setting_get --key=web_port) ] then ynh_app_setting_set --key=port --value=$(ynh_app_setting_get --key=web_port) ynh_app_setting_delete --key=web_port fi config_path=/etc/$app #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 755 $install_dir if [ -n $(ynh_app_setting_get --key=puma_worker_processes) ] then ynh_app_setting_delete --key=puma_worker_processes fi if [ -n $(ynh_app_setting_get --key=puma_max_threads) ] then ynh_app_setting_delete --key=puma_max_threads fi if [ -n $(ynh_app_setting_get --key=puma_min_threads) ] then ynh_app_setting_delete --key=puma_min_threads fi # If architecture doesn't exist, create it if [ -z "$architecture" ]; then if [ -n "$(uname -m | grep arm64)" ] || [ -n "$(uname -m | grep aarch64)" ]; then architecture="arm64" elif [ -n "$(uname -m | grep x86_64)" ]; then architecture="x86-64" elif [ -n "$(uname -m | grep 86)" ]; then ynh_die "GitLab is not compatible with x86 architecture" elif [ -n "$(uname -m | grep arm)" ]; then architecture="arm" else ynh_die "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 --key=architecture --value=$architecture fi # If client_max_body_size doesn't exist, create it if [ -z "$client_max_body_size" ]; then client_max_body_size="250m" ynh_app_setting_set --key=client_max_body_size --value=$client_max_body_size fi # if this source file exist, remove it if [ -e "/etc/apt/sources.list.d/gitlab-ce.list" ]; then ynh_safe_rm "/etc/apt/sources.list.d/gitlab-ce.list" fi #================================================= # ADD SWAP IF NEEDED #================================================= total_ram=$(ynh_get_ram --total) swap_needed=0 # https://docs.gitlab.com/ce/install/requirements.html#memory # Need at least 2Go of swap if [ $total_ram -lt 4096 ]; then swap_needed=2048 fi if [ $swap_needed -gt 0 ]; then ynh_script_progression "Adding $swap_needed Mo to swap..." if ! ynh_add_swap --size=$swap_needed; then ynh_print_warn "Please add $swap_needed Mo to swap to make GitLab work properly" fi fi #================================================= # CHECK IF KERNEL IS READ-ONLY #================================================= modify_kernel_parameters="true" for value_to_check in "kernel.shmall" "kernel.shmmax" "kernel.sem" "net.core.somaxconn" do if ! sysctl --write $value_to_check="$(sysctl --value $value_to_check)"; then modify_kernel_parameters="false" break fi done # For gitlab rb mkdir -p $config_path ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+") generated_external_url="https://$domain${path%/}" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= # FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed if ynh_app_upstream_version_changed then ynh_script_progression "Setting up source files..." # To avoid the automatic backup, already performed by YunoHost: https://docs.gitlab.com/omnibus/update/#updating-methods touch $config_path/skip-auto-backup current_version=$(grep gitlab-ce /opt/gitlab/version-manifest.txt | cut -d' ' -f2) # Load the last available version source $YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.last.sh last_version=$gitlab_version source_next_version () { # We start with the upgrade.$current_major_version.first.sh if [ -e "$YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.$current_major_version.first.sh" ]; then source $YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.$current_major_version.first.sh if dpkg --compare-versions "$gitlab_version" "gt" "$current_version"; then return fi fi # Then upgrade to all minor versions for minor_verion in $(ls $YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.$current_major_version* | grep -v -E ".first.sh$|.last.sh$" | sed -e "s@$YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.$current_major_version.@@" -e "s/.sh$//" | sort) do source $YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.$current_major_version.$minor_verion.sh if dpkg --compare-versions "$gitlab_version" "gt" "$current_version" then return fi done # Then end with upgrade.$current_major_version.last.sh if [ -e "$YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.$current_major_version.last.sh" ]; then source $YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.$current_major_version.last.sh if dpkg --compare-versions "$gitlab_version" "gt" "$current_version" then return fi else source $YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.last.sh if dpkg --compare-versions "$gitlab_version" "gt" "$current_version" then return fi fi # Increment the major version to upgrade to the next version if dpkg --compare-versions "$gitlab_version" "le" "$current_version"; then current_major_version=$(($current_major_version + 1)) source_next_version fi } # To upgrade GitLab from a major version A to a major version B, # we need to follow a specific path described here https://gitlab-com.gitlab.io/support/toolbox/upgrade-path/ # A.last -> B.first -> -> B.X -> B.Y -> B.last # While the current version is not the last version, do an upgrade while [ "$last_version" != "$current_version" ] do # https://docs.gitlab.com/ee/update/background_migrations.html if dpkg --compare-versions "$current_version" "ge" "15.1"; then checkBatchedBackgroundMigration=1 checkBackgroundMigration=0 else checkBatchedBackgroundMigration=0 checkBackgroundMigration=1 fi counter=0 while [ $checkBackgroundMigration -eq 1 ] || [ $checkBatchedBackgroundMigration -eq 1 ] do counter=$((counter + 1)) if [ $counter -gt 1200 ] then ynh_print_warn "Timeout: a background migration runs for at least 20min !" break fi if [ $checkBackgroundMigration -eq 1 ] && ((gitlab-rails runner -e production 'puts Gitlab::BackgroundMigration.remaining' | grep -q -w 0) || (gitlab-rails runner -e production 'puts Gitlab::Database::BackgroundMigration::BatchedMigration.queued.count' | grep -q -w 0)) then checkBackgroundMigration=0 fi if [ $checkBatchedBackgroundMigration -eq 1 ] && gitlab-psql -c "SELECT job_class_name, table_name, column_name, job_arguments FROM batched_background_migrations WHERE status NOT IN(3, 6);" | grep -q -w 0 then checkBatchedBackgroundMigration=0 fi ynh_print_info "Wait for the migration in the background to finish" sleep 1 done current_major_version=${current_version%%.*} source_next_version ynh_print_info "Upgrade from ${current_version} to ${gitlab_version}" ynh_config_add --template="$YNH_APP_BASEDIR/conf/$architecture.src.default" --destination="$YNH_APP_BASEDIR/conf/$architecture.src" tempdir="$(mktemp -d)" ynh_setup_source --dest_dir=$tempdir --source_id=$architecture if ! ynh_hide_warnings dpkg -i $tempdir/$gitlab_filename; then # This command will fail in lxc env package_check_action # defined in upgrade.d/upgrade.X.sh ynh_hide_warnings dpkg --configure gitlab-ce fi ynh_safe_rm "$tempdir" current_version=$(grep gitlab-ce /opt/gitlab/version-manifest.txt | cut -d' ' -f2) # Sometimes we need to update the gitlab.rb configuration file in order to migrate to the next version. if [ -e "$YNH_APP_BASEDIR/conf/gitlab.$current_major_version.rb" ]; then if [ -e "$YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.$current_major_version.last.sh" ]; then source $YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.$current_major_version.last.sh fi if dpkg --compare-versions "$gitlab_version" "ge" "$current_version"; then ynh_config_add --template="$YNH_APP_BASEDIR/conf/gitlab.$current_major_version.rb" --destination="$config_path/gitlab.rb" touch "$config_path/gitlab-persistent.rb" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown root:root "$config_path/gitlab-persistent.rb" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 640 "$config_path/gitlab-persistent.rb" # During large migrations, the logs are too big to be sent to paste.yunohost.org # Send the reconfigure logs in a file, and if the process succeeds, just delete it. gitlab-ctl reconfigure > "/tmp/gitlab_upgrade_$current_version.log" ynh_safe_rm "/tmp/gitlab_upgrade_$current_version.log" fi fi done fi #================================================= # RECONFIGURE GITLAB #================================================= ynh_script_progression "Reconfigure GitLab..." ynh_config_add --template="$YNH_APP_BASEDIR/conf/gitlab.rb" --destination="$config_path/gitlab.rb" touch "$config_path/gitlab-persistent.rb" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown root:root "$config_path/gitlab-persistent.rb" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 640 "$config_path/gitlab-persistent.rb" ynh_hide_warnings gitlab-ctl reconfigure # Allow ssh for git usermod -a -G "ssh.app" "git" #================================================= # NGINX CONFIGURATION #================================================= # Overwrite the nginx configuration only if it's allowed if [ $overwrite_nginx -eq 1 ] then ynh_script_progression "Configuring NGINX web server..." # Create a dedicated nginx config ynh_config_add_nginx client_max_body_size fi #================================================= # 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/puma/puma_stderr.log" "/var/log/$app/puma/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 #================================================= # FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed if ynh_app_upstream_version_changed then ynh_script_progression "Restarting GitLab..." ynh_systemctl --action=restart --service="gitlab-runsvdir" --log_path="/var/log/$app/puma/current" --wait_until="Listening on http://127.0.0.1:$port_puma" --timeout=300 fi #================================================= # RELOAD NGINX #================================================= ynh_systemctl --action=reload --service=nginx #================================================= # END OF SCRIPT #================================================= ynh_script_progression "Upgrade of GitLab completed"