mirror of
https://github.com/YunoHost-Apps/gitlab_ynh.git
synced 2024-09-03 18:36:35 +02:00
175 lines
6.5 KiB
Bash
175 lines
6.5 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
|
source ../settings/scripts/_common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
ynh_secure_remove "$tempdir" 2>&1
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_print_info "Loading settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
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)
|
|
architecture=$(ynh_app_setting_get "$app" architecture)
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
#=================================================
|
|
ynh_print_info "Validating restoration parameters..."
|
|
|
|
ynh_webpath_available $domain $path_url \
|
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
|
test ! -d $final_path \
|
|
|| ynh_die "There is already a directory: $final_path "
|
|
|
|
#=================================================
|
|
# STANDARD RESTORATION STEPS
|
|
#=================================================
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
#=================================================
|
|
# REINSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_print_info "Reinstalling dependencies..."
|
|
|
|
# Define and install dependencies
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# ADD SWAP IF NEEDED
|
|
#=================================================
|
|
ynh_print_info "Adding swap..."
|
|
|
|
total_memory=$(ynh_check_ram)
|
|
total_swap=$(ynh_check_ram --only_swap)
|
|
swap_needed=0
|
|
|
|
# https://docs.gitlab.com/ee/install/requirements.html#memory
|
|
if [ $total_memory -lt 8000 ]; then
|
|
# Need a minimum of 8Gb of memory
|
|
swap_needed=$((8000 - $total_memory))
|
|
fi
|
|
|
|
# Need at least 2Gb of swap
|
|
if [ $(($total_swap + $swap_needed)) -lt 2000 ]; then
|
|
swap_needed=$((2000 - $total_swap))
|
|
fi
|
|
|
|
ynh_print_info "Adding $swap_needed to swap..."
|
|
ynh_add_swap $swap_needed
|
|
|
|
#=================================================
|
|
# RESTORE CONF FILES
|
|
#=================================================
|
|
ynh_print_info "Restoring configuration files of Gitlab..."
|
|
|
|
ynh_restore_file "$config_path/gitlab-secrets.json"
|
|
ynh_restore_file "$config_path/gitlab.rb"
|
|
ynh_restore_file "$config_path/gitlab-persistent.rb"
|
|
|
|
#=================================================
|
|
# RESTORE THE APP MAIN DIR
|
|
#=================================================
|
|
ynh_print_info "Reinstalling gitlab..."
|
|
|
|
update_src_version() {
|
|
source ../settings/scripts/upgrade.d/upgrade.last.sh
|
|
mkdir -p ../conf/
|
|
cp ../settings/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"
|
|
|
|
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
|
|
}
|
|
|
|
update_src_version
|
|
|
|
tempdir="$(mktemp -d)"
|
|
|
|
ynh_setup_source $tempdir $architecture
|
|
|
|
if IS_PACKAGE_CHECK; then
|
|
if ! dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env
|
|
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
|
|
fi
|
|
else
|
|
dpkg -i $tempdir/$gitlab_filename
|
|
fi
|
|
|
|
#=================================================
|
|
# SPECIFIC RESTORATION
|
|
#=================================================
|
|
# RESTORE GITLAB DATABASE
|
|
#=================================================
|
|
ynh_print_info "Restoring Gitlab..."
|
|
|
|
ynh_restore_file "/var/opt/$app/backups/last_gitlab_backup.tar"
|
|
|
|
last_backup="last"
|
|
|
|
gitlab-ctl stop unicorn
|
|
gitlab-ctl stop sidekiq
|
|
|
|
# Use gitlab-rake to backup
|
|
ynh_exec_warn_less gitlab-rake gitlab:backup:restore force=yes BACKUP=$last_backup
|
|
|
|
gitlab-rake gitlab:check SANITIZE=true
|
|
|
|
#=================================================
|
|
# 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" --line_match="adopted" --timeout=3600
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_print_info "Reloading nginx web server..."
|
|
|
|
ynh_systemd_action --action=reload --service_name=nginx
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_print_info "Restoration completed for $app"
|