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"
|
2019-05-23 09:01:14 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
port=$(ynh_app_setting_get --app="$app" --key=web_port)
|
|
|
|
portUnicorn=$(ynh_app_setting_get --app="$app" --key=unicorn_port)
|
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
total_memory=$(ynh_check_ram)
|
|
|
|
total_swap=$(ynh_check_ram --only_swap)
|
|
|
|
swap_needed=0
|
|
|
|
|
|
|
|
# https://docs.gitlab.com/ee/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
|
|
|
|
#=================================================
|
2019-05-09 09:03:19 +02: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
|
|
|
|
#=================================================
|
2019-05-11 01:42:05 +02: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"
|
|
|
|
|
|
|
|
if [ $architecture = "x86-64" ]; then
|
|
|
|
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_x86_64_source_sha256" --target_file="../conf/$architecture.src"
|
|
|
|
elif [ $architecture = "arm" ]; then
|
|
|
|
ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_arm_source_sha256" --target_file="../conf/$architecture.src"
|
|
|
|
fi
|
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-05-12 20:08:00 +02:00
|
|
|
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
2019-05-12 19:36:00 +02:00
|
|
|
if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ;
|
|
|
|
then # This command will fail in lxc env
|
2019-06-23 16:33:48 +02:00
|
|
|
ynh_replace_string --match_string="command \"sysctl -e --system\"" --replace_string="command \"sysctl -e --system || true\"" --target_file="$final_path/embedded/cookbooks/package/resources/sysctl.rb"
|
2019-05-09 01:13:48 +02:00
|
|
|
ynh_exec_warn_less dpkg --configure gitlab-ce
|
2019-03-17 20:14:06 +01:00
|
|
|
fi
|
2019-03-16 02:38:12 +01:00
|
|
|
else
|
2019-05-09 01:13:48 +02:00
|
|
|
ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename
|
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
|
|
|
#=================================================
|
2019-05-09 09:03:19 +02: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
|
|
|
|
2018-12-25 20:55:11 +01:00
|
|
|
gitlab-ctl stop unicorn
|
|
|
|
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-03-17 20:15:14 +01:00
|
|
|
ynh_exec_warn_less gitlab-rake gitlab:backup:restore force=yes BACKUP=$last_backup
|
|
|
|
|
2019-03-24 21:36:20 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
2019-03-28 12:18:58 +01: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/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"
|
2019-03-19 00:12:44 +01:00
|
|
|
|
2019-03-24 21:36:20 +01:00
|
|
|
#=================================================
|
|
|
|
# WAITING GITLAB
|
|
|
|
#=================================================
|
2019-05-09 09:03:19 +02:00
|
|
|
ynh_script_progression --message="Waiting for gitlab..." --weight=14
|
2019-03-19 00:12:44 +01:00
|
|
|
|
2019-03-25 01:36:16 +01:00
|
|
|
ynh_systemd_action --action=restart --service_name="gitlab-runsvdir" --log_path="/var/log/$app/unicorn/current" --line_match="adopted" --timeout=3600
|
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
|
|
|
|
#=================================================
|
2019-05-09 09:03:19 +02: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
|