#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= if [ ! -e _common.sh ]; then # Fetch helpers file if not in current directory cp ../settings/scripts/_common.sh ./_common.sh chmod a+rx _common.sh fi source /usr/share/yunohost/helpers source _common.sh #================================================= # MANAGE SCRIPT FAILURE #================================================= # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) db_name=$(ynh_app_setting_get $app db_name) db_pwd=$(ynh_app_setting_get $app db_pwd) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die "There is already a directory: $final_path " # Check memory requirements check_memory_requirements #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE ALL FILES #================================================= # Restore all config and data ynh_restore #================================================= # REINSTALL DEPENDENCIES #================================================= ynh_install_app_dependencies "$pkg_dependencies" #================================================= # INSTALL RUBY #================================================= ynh_install_ruby $RUBY_VERSION #================================================= # REINSTALL BUNDLE GEM #================================================= (cd "$final_path" gem install bundler) #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= ynh_psql_test_if_first_run ynh_psql_test_if_first_run ynh_psql_setup_db "$db_name" "$db_name" "$db_pwd" # Set extensions ynh_psql_execute_as_root "\connect $db_name CREATE EXTENSION IF NOT EXISTS hstore; CREATE EXTENSION IF NOT EXISTS pg_trgm;" # Restore dump ynh_psql_execute_file_as_root ./db.sql "$db_name" #================================================= # RESTORE SYSTEMD #================================================= systemctl daemon-reload systemctl enable $app.service #================================================= # SETUP LOGROTATE #================================================= ynh_use_logrotate #================================================= # RECREATE OF THE DEDICATED USER #================================================= # Create a system user allowing login (if not existing) ynh_system_user_create $app $final_path 1 #================================================= # RESTORE USER RIGHTS #================================================= chown -R $app: $final_path chown -R $app: /var/log/$app #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= yunohost service add $app --log "$final_path/log/unicorn.stderr.log" #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND DISCOURSE #================================================= if [ -n "$(uname -m | grep arm)" ] ; then unicorn_workers=2 else unicorn_workers=3 fi # Wait for discourse to be fully started ynh_check_starting "INFO -- : worker=$((unicorn_workers-1)) ready" "$final_path/log/unicorn.stderr.log" "120" "$app" systemctl reload nginx