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/restore

175 lines
7.4 KiB
Text
Raw Normal View History

2017-06-10 10:10:31 +02:00
#!/bin/bash
2018-12-24 16:25:49 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2017-06-10 10:10:31 +02:00
2019-03-16 02:38:12 +01:00
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
2019-01-22 16:05:08 +01:00
source /usr/share/yunohost/helpers
2019-02-09 22:18:57 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2019-03-16 02:38:12 +01:00
ynh_clean_setup () {
2019-05-09 01:13:48 +02:00
ynh_exec_warn_less ynh_secure_remove --file="$tempdir"
ynh_clean_check_starting
2019-02-09 22:18:57 +01:00
}
2019-01-22 16:05:08 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2018-12-24 16:25:49 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2019-05-09 09:03:19 +02:00
ynh_script_progression --message="Loading settings..." --weight=1
2019-03-16 02:38:12 +01:00
app=$YNH_APP_INSTANCE_NAME
2018-12-24 16:25:49 +01:00
2019-05-09 01:13:48 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
2020-05-23 01:04:34 +02:00
portPuma=$(ynh_app_setting_get --app="$app" --key=puma_port)
2019-05-09 01:13:48 +02:00
architecture=$(ynh_app_setting_get --app="$app" --key=architecture)
2018-12-24 19:10:30 +01:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2019-05-09 09:03:19 +02:00
ynh_script_progression --message="Validating restoration parameters..." --weight=1
2018-12-24 19:10:30 +01:00
2019-05-09 01:13:48 +02:00
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
2019-03-16 02:38:12 +01:00
test ! -d $final_path \
2019-05-09 01:13:48 +02:00
|| ynh_die --message="There is already a directory: $final_path "
2018-12-24 16:25:49 +01:00
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
2019-05-09 01:13:48 +02:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2018-12-24 16:25:49 +01:00
2018-12-24 19:10:30 +01:00
#=================================================
2018-12-25 20:55:11 +01:00
# REINSTALL DEPENDENCIES
2018-12-24 19:10:30 +01:00
#=================================================
2019-05-09 09:03:19 +02:00
ynh_script_progression --message="Reinstalling dependencies..." --weight=5
2018-12-24 19:10:30 +01:00
2019-03-16 02:38:12 +01:00
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
2018-12-25 19:22:24 +01:00
2019-05-06 21:17:27 +02:00
#=================================================
# ADD SWAP IF NEEDED
#=================================================
2020-05-02 14:16:08 +02:00
total_memory=$(ynh_get_ram --total)
total_swap=$(ynh_get_ram --total --only_swap)
2019-05-06 21:17:27 +02:00
swap_needed=0
2019-08-23 21:44:38 +02:00
# https://docs.gitlab.com/ce/install/requirements.html#memory
2019-05-07 00:37:07 +02:00
if [ $total_memory -lt 8192 ]; then
2019-05-07 00:51:34 +02:00
# Need a minimum of 8Go of memory
2019-05-07 00:37:07 +02:00
swap_needed=$((8192 - $total_memory))
2019-05-06 21:17:27 +02:00
fi
2019-05-07 00:37:07 +02:00
# Need at least 2Go of swap
if [ $(($total_swap + $swap_needed)) -lt 2048 ]; then
swap_needed=$((2048 - $total_swap))
2019-05-06 21:17:27 +02:00
fi
2019-05-11 01:41:46 +02:00
ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1
ynh_add_swap --size=$swap_needed
2019-05-06 21:17:27 +02:00
2018-12-25 20:55:11 +01:00
#=================================================
# RESTORE CONF FILES
#=================================================
2020-12-23 17:08:21 +01:00
ynh_script_progression --message="Restoring configuration files of GitLab..." --weight=1
2019-01-26 14:30:58 +01:00
2019-05-09 01:13:48 +02:00
ynh_restore_file --origin_path="$config_path/gitlab-secrets.json"
ynh_restore_file --origin_path="$config_path/gitlab.rb"
ynh_restore_file --origin_path="$config_path/gitlab-persistent.rb"
2018-12-25 20:08:49 +01:00
2018-12-25 20:55:11 +01:00
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
2020-12-23 17:08:21 +01:00
ynh_script_progression --message="Reinstalling GitLab..." --weight=200
2019-03-16 02:38:12 +01:00
2019-05-12 19:36:00 +02:00
source ../settings/scripts/upgrade.d/upgrade.last.sh
mkdir -p ../conf/
cp ../settings/conf/$architecture.src.default ../conf/$architecture.src
ynh_replace_string --match_string="__VERSION__" --replace_string="$gitlab_version" --target_file="../conf/$architecture.src"
ynh_replace_string --match_string="__SOURCE_FILENAME__" --replace_string="$gitlab_filename" --target_file="../conf/$architecture.src"
2020-10-12 19:50:47 +02:00
ynh_replace_string --match_string="__DEBIAN_VERSION__" --replace_string="$gitlab_debian_version" --target_file="../conf/$architecture.src"
2020-07-15 17:07:20 +02:00
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_source_sha256" --target_file="../conf/$architecture.src"
2018-12-25 20:55:11 +01:00
2019-03-16 02:38:12 +01:00
tempdir="$(mktemp -d)"
2018-12-24 19:55:59 +01:00
2019-05-09 01:13:48 +02:00
ynh_setup_source --dest_dir=$tempdir --source_id=$architecture
2019-03-16 02:38:12 +01:00
2019-07-31 10:25:20 +02:00
if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ;
then # This command will fail in lxc env
package_check_action # defined in upgrade.d/upgrade.last.sh
ynh_exec_warn_less dpkg --configure gitlab-ce
2019-03-16 02:38:12 +01:00
fi
2018-12-24 19:10:30 +01:00
2018-12-24 19:31:51 +01:00
#=================================================
2018-12-24 19:55:59 +01:00
# SPECIFIC RESTORATION
#=================================================
2018-12-25 20:55:11 +01:00
# RESTORE GITLAB DATABASE
2018-12-24 19:31:51 +01:00
#=================================================
2020-12-23 17:08:21 +01:00
ynh_script_progression --message="Restoring GitLab..." --weight=55
2019-01-26 14:30:58 +01:00
2019-05-09 01:13:48 +02:00
ynh_restore_file --origin_path="/var/opt/$app/backups/last_gitlab_backup.tar"
2019-03-16 02:38:12 +01:00
last_backup="last"
2018-12-24 16:25:49 +01:00
2020-05-23 01:04:34 +02:00
gitlab-ctl stop puma
2018-12-25 20:55:11 +01:00
gitlab-ctl stop sidekiq
2018-12-24 16:25:49 +01:00
# Use gitlab-rake to backup
2019-06-03 11:06:18 +02:00
# Doc: https://docs.gitlab.com/ce/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installations
2019-08-23 21:44:38 +02:00
ynh_exec_warn_less gitlab-backup restore force=yes BACKUP=$last_backup
# https://docs.gitlab.com/ce/raketasks/backup_restore.html#container-registry-push-failures-after-restoring-from-a-backup
2019-08-27 00:10:39 +02:00
if ynh_user_exists --username="registry" && [ -d "/var/opt/gitlab/gitlab-rails/shared/registry/docker" ]; then
chown -R registry:registry /var/opt/gitlab/gitlab-rails/shared/registry/docker
fi
2019-03-17 20:15:14 +01:00
2019-03-24 21:36:20 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
2020-05-23 01:04:34 +02:00
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"
2019-03-19 00:12:44 +01:00
2019-03-24 21:36:20 +01:00
#=================================================
# WAITING GITLAB
#=================================================
2020-12-23 17:08:21 +01:00
ynh_script_progression --message="Waiting for GitLab..." --weight=14
2019-03-19 00:12:44 +01:00
2020-05-23 01:04:34 +02:00
ynh_systemd_action --action=restart --service_name="gitlab-runsvdir" --log_path="/var/log/$app/puma/current" --line_match="Listening on tcp://127.0.0.1:$portPuma" --timeout=300
2019-03-19 00:12:44 +01:00
2019-06-05 00:33:32 +02:00
#=================================================
# CHECK THE RESTORED DATA
#=================================================
gitlab-rake gitlab:check SANITIZE=true
2018-12-25 20:55:11 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-12-23 17:08:21 +01:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2019-03-16 02:38:12 +01:00
ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# END OF SCRIPT
#=================================================
2018-12-25 20:55:11 +01:00
2019-05-09 09:03:19 +02:00
ynh_script_progression --message="Restoration completed for $app" --last