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

237 lines
8.2 KiB
Text
Raw Normal View History

2017-06-10 10:10:31 +02:00
#!/bin/bash
2018-12-19 00:02:20 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2018-12-19 00:02:20 +01:00
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Load common variables and helpers
source ./_common.sh
2017-06-10 10:10:31 +02:00
2018-12-19 00:02:20 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2017-06-10 10:10:31 +02:00
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)
2019-03-16 02:38:12 +01:00
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)
2019-03-16 02:38:12 +01:00
architecture=$(ynh_app_setting_get "$app" architecture)
2017-06-10 10:10:31 +02:00
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-03 14:29:53 +01:00
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
is_public=0
fi
2019-03-16 02:38:12 +01:00
# 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
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
fi
# If architecture doesn't exist, create it
if [ -z "$architecture" ]; then
# Detect the system architecture
if [ -n "$(uname -m | grep 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 $app architecture $architecture
fi
2019-03-03 14:29:53 +01:00
# If domain doesn't exist, retrieve it
2019-03-03 15:03:26 +01:00
if [ -z "$domain" ]; then
2019-03-03 14:29:53 +01:00
domain=$(grep "external_url" "/etc/gitlab/gitlab.rb" | cut -d'/' -f3) # retrieve $domain from conf file
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
fi
# If path_url doesn't exist, retrieve it
2019-03-03 15:03:26 +01:00
if [ -z "$path_url" ]; then
2019-03-03 14:38:46 +01:00
path_url=$(grep "location" "/etc/nginx/conf.d/${domain}.d/gitlab.conf" | cut -d' ' -f2)
2019-03-03 14:29:53 +01:00
path_url=$(ynh_normalize_url_path $path_url)
ynh_app_setting_set $app path_url path_url
fi
# If port doesn't exist, retrieve it
2019-03-03 15:03:26 +01:00
if [ -z "$port" ]; then
2019-03-03 14:38:46 +01:00
port=$(grep -F "nginx['listen_port']" "/etc/gitlab/gitlab.rb" | cut -d' ' -f3)
2019-03-03 14:29:53 +01:00
ynh_app_setting_set $app web_port $port
fi
# If port doesn't exist, retrieve it
2019-03-03 15:03:26 +01:00
if [ -z "$portUnicorn" ]; then
2019-03-03 14:38:46 +01:00
portUnicorn=$(grep -F "unicorn['port']" "/etc/gitlab/gitlab.rb" | cut -d' ' -f3)
2019-03-03 14:29:53 +01:00
ynh_app_setting_set $app unicorn_port $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"
fi
#=================================================
2018-12-19 00:02:20 +01:00
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Backing up the app before upgrading (may take a while)..."
2018-12-19 00:02:20 +01:00
# Backup the current version of the app
ynh_backup_before_upgrade
2019-03-16 02:38:12 +01:00
ynh_clean_setup () {
ynh_secure_remove "$tempdir" 2>&1
ynh_clean_check_starting
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
2018-12-19 00:02:20 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
2019-03-16 02:38:12 +01:00
# INSTALL DEPENDENCIES
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Installing dependencies..."
2018-12-19 00:02:20 +01:00
2019-03-16 02:38:12 +01:00
ynh_install_app_dependencies $pkg_dependencies
2017-06-10 10:10:31 +02:00
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
# PRECONFIGURE GITLAB
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Preconfigure gitlab..."
ynh_backup_if_checksum_is_different "$config_path/gitlab.rb"
mkdir -p $config_path
cp -f ../conf/gitlab.rb "$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 "__PORTUNICORN__" "$portUnicorn" "$config_path/gitlab.rb"
2017-06-10 10:10:31 +02:00
2019-03-16 02:38:12 +01:00
ynh_store_file_checksum "$config_path/gitlab.rb"
2017-06-10 10:10:31 +02:00
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Setting up source files..."
2018-12-19 00:02:20 +01:00
2019-03-16 02:38:12 +01:00
update_src_version() {
source ./upgrade.d/upgrade.last.sh
2019-03-16 12:28:47 +01:00
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"
2019-03-16 13:17:15 +01:00
if [ $architecture = "x86-64" ]; then
ynh_replace_string "__SHA256_SUM__" "$gitlab_x86_64_source_sha256" "../conf/$architecture.src"
elif [ $architecture = "arm" ]; then
ynh_replace_string "__SHA256_SUM__" "$gitlab_arm_source_sha256" "../conf/$architecture.src"
fi
2019-03-16 02:38:12 +01:00
}
update_src_version
tempdir="$(mktemp -d)"
ynh_setup_source $tempdir $architecture
if IS_PACKAGE_CHECK; then
2019-03-17 21:03:20 +01:00
if ! dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env
2019-03-17 20:15:14 +01:00
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
2019-03-17 20:14:06 +01:00
fi
2019-03-16 02:38:12 +01:00
else
dpkg -i $tempdir/$gitlab_filename
fi
2017-06-10 10:10:31 +02:00
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
# NGINX CONFIGURATION
2018-12-19 00:02:20 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Configuring nginx web server..."
2017-06-10 10:10:31 +02:00
2019-03-16 02:38:12 +01:00
# Create a dedicated nginx config
ynh_add_nginx_config
2018-04-14 18:38:22 +02:00
2018-12-19 00:02:20 +01:00
#=================================================
# GENERIC FINALIZATION
2019-03-24 21:36:20 +01:00
#=================================================
# 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"
2018-12-19 00:02:20 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2017-06-10 10:10:31 +02:00
# If app is public, add url to SSOWat conf as skipped_uris
2019-03-24 21:36:20 +01:00
if [ $is_public -eq 1 ]; then
2019-01-26 14:46:52 +01:00
# See install script
ynh_app_setting_set "$app" unprotected_uris "/"
2017-06-10 10:10:31 +02:00
fi
2019-03-16 02:38:12 +01:00
#=================================================
2019-03-24 21:36:20 +01:00
# WAITING GITLAB
2019-03-16 02:38:12 +01:00
#=================================================
2019-03-19 00:12:44 +01:00
ynh_print_info "Waiting for gitlab..."
2019-03-16 02:38:12 +01:00
2019-03-24 21:36:20 +01:00
# 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
2019-03-16 02:38:12 +01:00
2018-12-19 00:02:20 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Reloading nginx web server..."
2018-12-19 00:02:20 +01:00
2019-03-16 02:38:12 +01:00
ynh_systemd_action --action=reload --service_name=nginx
2019-01-05 11:12:03 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
# END OF SCRIPT
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Upgrade of $app completed"