2018-04-07 12:02:34 +02:00
|
|
|
#!/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
|
2018-04-24 17:45:19 +02:00
|
|
|
source _common.sh
|
2018-04-07 12:02:34 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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 "
|
|
|
|
|
2018-04-30 18:53:20 +02:00
|
|
|
# Check memory requirements
|
|
|
|
check_memory_requirements
|
|
|
|
|
2018-04-07 12:02:34 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE ALL FILES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Restore all config and data
|
|
|
|
ynh_restore
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_install_app_dependencies "$pkg_dependencies"
|
|
|
|
|
2018-04-24 21:27:56 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL RUBY
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_install_ruby $RUBY_VERSION
|
|
|
|
|
2018-04-07 12:02:34 +02:00
|
|
|
#=================================================
|
|
|
|
# REINSTALL BUNDLE GEM
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
(cd "$final_path"
|
|
|
|
gem install bundler)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE POSTGRESQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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
|
2018-05-04 12:51:16 +02:00
|
|
|
systemctl enable $app.service
|
2018-04-07 12:02:34 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RECREATE OF THE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
2018-04-24 21:27:56 +02:00
|
|
|
# Create a system user allowing login (if not existing)
|
|
|
|
ynh_system_user_create $app $final_path 1
|
2018-04-07 12:02:34 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE USER RIGHTS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
chown -R $app: $final_path
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
2018-05-23 21:22:00 +02:00
|
|
|
yunohost service add $app --log "$final_path/log/unicorn.stderr.log" "$final_path/log/unicorn.stdout.log" "$final_path/log/production.log"
|
2018-04-07 12:02:34 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX AND DISCOURSE
|
|
|
|
#=================================================
|
|
|
|
|
2018-05-04 12:51:16 +02:00
|
|
|
if [ -n "$(uname -m | grep arm)" ] ; then
|
|
|
|
unicorn_workers=2
|
|
|
|
else
|
|
|
|
unicorn_workers=3
|
|
|
|
fi
|
|
|
|
# Wait for discourse to be fully started
|
2018-07-01 10:05:00 +02:00
|
|
|
ynh_check_starting "INFO -- : worker=$((unicorn_workers-1)) ready" "$final_path/log/unicorn.stderr.log" "240" "$app"
|
2018-05-04 12:51:16 +02:00
|
|
|
|
2018-04-07 12:02:34 +02:00
|
|
|
|
|
|
|
systemctl reload nginx
|