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.5 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
2021-05-15 21:44:39 +02:00
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_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
# Need at least 2Go of swap
2021-02-25 13:25:08 +01:00
if [ $total_swap -lt 2048 ]; then
swap_needed=$((2048 - total_swap))
2019-05-06 21:17:27 +02:00
fi
2021-02-25 13:25:08 +01:00
if [ $swap_needed -gt 0 ]; then
ynh_script_progression --message="Adding $swap_needed Mo to swap..."
2021-05-15 15:33:14 +02:00
if ! ynh_add_swap --size=$swap_needed; then
ynh_print_warn --message="Please add $swap_needed Mo to swap to make Gitlab work properly"
fi
2021-02-25 13:25:08 +01:00
fi
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:14:33 +01:00
ynh_script_progression --message="Reinstalling GitLab..." --weight=50
2019-03-16 02:38:12 +01:00
2021-05-15 17:05:49 +02:00
source $YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.last.sh
cp $YNH_APP_BASEDIR/conf/$architecture.src.default $YNH_APP_BASEDIR/conf/$architecture.src
ynh_replace_string --match_string="__VERSION__" --replace_string="$gitlab_version" --target_file="$YNH_APP_BASEDIR/conf/$architecture.src"
ynh_replace_string --match_string="__SOURCE_FILENAME__" --replace_string="$gitlab_filename" --target_file="$YNH_APP_BASEDIR/conf/$architecture.src"
ynh_replace_string --match_string="__DEBIAN_VERSION__" --replace_string="$gitlab_debian_version" --target_file="$YNH_APP_BASEDIR/conf/$architecture.src"
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_source_sha256" --target_file="$YNH_APP_BASEDIR/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:14:33 +01:00
ynh_script_progression --message="Restoring GitLab..." --weight=35
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
2021-01-28 01:05:03 +01:00
ynh_systemd_action --action=restart --service_name="gitlab-runsvdir" --log_path="/var/log/$app/puma/current" --line_match="Listening on http://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
2021-05-15 11:00:03 +02:00
# Allow ssh for git
usermod -a -G "ssh.app" "git"
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
2020-12-23 17:18:58 +01:00
ynh_script_progression --message="Restoration completed for GitLab" --last