#!/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 #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$install_dir" chown -R $app:$app "$install_dir" #================================================= # RESTORE THE DATA DIRECTORY #================================================= ynh_script_progression --message="Restoring the data directory..." if system_is_inside_container then # to be sure to not exceed size limit, i use a virtual disk with a fix size to have a max limit size. qemu-img create -f qcow2 $data_dir/garage_data.qcow2 "$weight"G $install_dir/mount_disk.sh true fi chown -R $app:$app "$data_dir" #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= ynh_script_progression --message="Restoring the NGINX web server configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #add wildcard subdomain ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/98-nginx_$app" yunohost tools regen-conf nginx ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet ynh_restore_file --origin_path="/etc/logrotate.d/$app" yunohost service add $app --description="s3 storage" --log="/var/log/$app/$app.log" --needs_exposed_ports $port #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." #recreate log folder mkdir /var/log/$app ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" #================================================= # RECREATE CONFIGURATION #================================================= i=0 # sometimes server need some time to start while [ -z "$($garage node id -q 2>/dev/null | cut -d '@' -f1)" ]; do i=$(( i + 1 )) [ $i -le 30 ] || { $garage node id || true; ynh_die --message="unable to get node id"; } sleep 1 done # restoring garage can lead to change node id secret_node_id=$($garage node id -q 2>/dev/null | cut -d '@' -f1) ynh_app_setting_set --app=$app --key=secret_node_id --value=$secret_node_id # define node $garage layout assign $secret_node_id -z $domain -c ${weight}GB -t $domain # if there is enough node, apply layout garage_layout_apply if [ -n "$bootstrap_peers" ] then garage_connect "$bootstrap_peers" fi #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Restoration completed for $app" --last