#!/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 #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) config_path=$(ynh_app_setting_get --app=$app --key=config_path) datadir=$(ynh_app_setting_get --app=$app --key=datadir) node_type=$(ynh_app_setting_get --app=$app --key=node_type) http_port=$(ynh_app_setting_get --app=$app --key=http_port) rpc_port=$(ynh_app_setting_get --app=$app --key=rpc_port) serf_port=$(ynh_app_setting_get --app=$app --key=serf_port) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= ynh_script_progression --message="Validating restoration parameters..." #================================================= # STANDARD RESTORATION STEPS #================================================= # RECREATE THE DEDICATED USER #================================================= ynh_script_progression --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) ynh_system_user_create --username=$app #================================================= # RESTORE THE DATA DIRECTORY #================================================= ynh_script_progression --message="Restoring the data directory..." ynh_restore_file --origin_path="$datadir" --not_mandatory mkdir -p $datadir chmod 750 "$datadir" chmod -R o-rwx "$datadir" chown -R $app:$app "$datadir" #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Reinstalling dependencies..." if [ "$node_type" == "client" ] then ynh_install_app_dependencies $client_pkg_dependencies fi ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg" #================================================= # 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" #================================================= # RESTORE VARIOUS FILES #================================================= ynh_script_progression --message="Restoring various files..." ynh_restore_file --origin_path="$config_path" chmod 750 "$config_path" chmod -R o-rwx "$config_path" chown -R $app:$app "$config_path" # Open the port ynh_script_progression --message="Configuring firewall..." ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $rpc_port if [ "$node_type" == "server" ] then ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $serf_port fi if [ "$node_type" == "client" ] then lxc_bridge=$(ynh_app_setting_get --app=$app --key=lxc_bridge) plage_ip=$(ynh_app_setting_get --app=$app --key=plage_ip) main_iface=$(sudo ip route | grep default | awk '{print $5;}') ynh_app_setting_set --app=$app --key=main_iface --value=$main_iface ynh_add_config --template="../conf/lxc_bridge" --destination="/etc/network/interfaces.d/$lxc_bridge" ifup $lxc_bridge --interfaces=/etc/network/interfaces.d/$lxc_bridge iptables -A FORWARD -i $lxc_bridge -o $main_iface -j ACCEPT iptables -A FORWARD -i $main_iface -o $lxc_bridge -j ACCEPT iptables -t nat -A POSTROUTING -s $plage_ip.0/24 -j MASQUERADE fi #================================================= # RESTORE SYSTEMD #================================================= ynh_script_progression --message="Restoring the systemd configuration..." ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= ynh_script_progression --message="Restoring the logrotate configuration..." ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Nomad agent started" #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= 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"