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
|
|
|
|
|
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
|
|
|
|
2019-05-06 21:17:27 +02:00
|
|
|
#=================================================
|
|
|
|
# ADD SWAP IF NEEDED
|
|
|
|
#=================================================
|
|
|
|
|
2023-10-27 11:52:56 +02:00
|
|
|
total_ram=$(ynh_get_ram --total)
|
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
|
2023-10-27 11:52:56 +02:00
|
|
|
if [ $total_ram -lt 4096 ]; then
|
|
|
|
swap_needed=2048
|
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
|
2023-08-28 15:00:42 +02:00
|
|
|
ynh_print_warn --message="Please add $swap_needed Mo to swap to make GitLab work properly"
|
2021-05-15 15:33:14 +02:00
|
|
|
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
|
|
|
|
2023-03-03 11:24:16 +01:00
|
|
|
config_path=/etc/$app
|
2023-03-30 10:41:18 +02:00
|
|
|
chmod 755 $install_dir
|
|
|
|
|
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
|
2021-05-28 16:13:02 +02:00
|
|
|
ynh_add_config --template="$YNH_APP_BASEDIR/conf/$architecture.src.default" --destination="$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
|
|
|
|
2023-03-04 23:12:11 +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:$port_puma" --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
|