2017-08-17 15:17:45 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-03-11 14:15:23 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
2017-08-17 15:17:45 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ ! -e _common.sh ]; then
|
2018-03-11 14:15:23 +01:00
|
|
|
# Get the _common.sh file if it's not in the current directory
|
|
|
|
cp ../settings/scripts/_common.sh ./_common.sh
|
|
|
|
chmod a+rx _common.sh
|
2017-08-17 15:17:45 +02:00
|
|
|
fi
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2018-03-11 14:15:23 +01:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-08-17 15:17:45 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
2018-03-11 14:15:23 +01:00
|
|
|
db_name=$(ynh_app_setting_get $app db_name)
|
2017-08-17 15:17:45 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
|
|
|
|
2018-03-11 14:15:23 +01:00
|
|
|
ynh_webpath_available $domain $path_url \
|
2017-08-17 15:17:45 +02:00
|
|
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
|
|
|
test ! -d $final_path \
|
2018-03-11 14:15:23 +01:00
|
|
|
|| ynh_die "There is already a directory: $final_path "
|
2017-08-17 15:17:45 +02:00
|
|
|
|
2018-03-11 14:15:23 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
2017-08-17 15:17:45 +02:00
|
|
|
|
|
|
|
#=================================================
|
2018-03-11 14:15:23 +01:00
|
|
|
# RESTORE THE APP MAIN DIR
|
2017-08-17 15:17:45 +02:00
|
|
|
#=================================================
|
2018-03-11 14:15:23 +01:00
|
|
|
|
|
|
|
ynh_restore_file "$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
2017-08-17 15:17:45 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-03-11 14:15:23 +01:00
|
|
|
# Create the dedicated user (if not existing)
|
|
|
|
ynh_system_user_create $app
|
2017-08-17 15:17:45 +02:00
|
|
|
|
|
|
|
#=================================================
|
2018-03-11 14:15:23 +01:00
|
|
|
# RESTORE USER RIGHTS
|
2017-08-17 15:17:45 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-03-11 14:15:23 +01:00
|
|
|
# Restore permissions on app files
|
|
|
|
chown -R $app:$app $final_path
|
2017-08-17 15:17:45 +02:00
|
|
|
|
|
|
|
#=================================================
|
2018-03-11 14:15:23 +01:00
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
2017-08-17 15:17:45 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-03-11 14:15:23 +01:00
|
|
|
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
|
|
|
|
echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.6 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
|
|
|
|
sudo apt-get update
|
|
|
|
ynh_install_app_dependencies mongodb-org
|
2017-08-17 15:17:45 +02:00
|
|
|
|
|
|
|
#=================================================
|
2018-03-11 14:15:23 +01:00
|
|
|
# RESTORE THE MYSQL DATABASE
|
2017-08-17 15:17:45 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-03-11 14:15:23 +01:00
|
|
|
pushd $final_path
|
|
|
|
datebackup=$(ynh_app_setting_get $app datebackup)
|
|
|
|
mongorestore mongo_backup$datebackup/
|
|
|
|
ynh_secure_remove mongo_backup$datebackup/
|
|
|
|
popd
|
2017-08-17 15:17:45 +02:00
|
|
|
|
|
|
|
#=================================================
|
2018-03-11 14:15:23 +01:00
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
2017-08-17 15:17:45 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-03-11 14:15:23 +01:00
|
|
|
yunohost service add $app --log "/var/log/$app/APP.log"
|
2017-08-17 15:17:45 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL NODEJS
|
|
|
|
#=================================================
|
2018-03-11 14:15:23 +01:00
|
|
|
|
2017-08-17 15:17:45 +02:00
|
|
|
ynh_install_nodejs $NODEJS_VERSION
|
|
|
|
|
|
|
|
#=================================================
|
2018-03-11 14:15:23 +01:00
|
|
|
# RESTORE SYSTEMD
|
2017-08-17 15:17:45 +02:00
|
|
|
#=================================================
|
2018-03-11 14:15:23 +01:00
|
|
|
|
|
|
|
ynh_restore_file "/etc/systemd/system/$app.service"
|
|
|
|
systemctl enable $app.service
|
|
|
|
systemctl start $app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_restore_file "/etc/logrotate.d/$app"
|
|
|
|
|
2017-08-17 15:17:45 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2018-03-11 14:15:23 +01:00
|
|
|
# RELOAD NGINX AND PHP-FPM
|
2017-08-17 15:17:45 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-03-11 14:15:23 +01:00
|
|
|
systemctl reload php5-fpm
|
|
|
|
systemctl reload nginx
|