1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00

scripts: add restore script

This commit is contained in:
Pierre de La Morinerie 2017-09-11 15:35:16 +05:30
parent 74c9a8231e
commit d0b367752a
3 changed files with 111 additions and 2 deletions

View file

@ -10,6 +10,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path="/var/www/$app" final_path="/var/www/$app"

96
scripts/restore Normal file
View file

@ -0,0 +1,96 @@
#!/bin/bash
set -eu # exit on error ; treat unset variables as error
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
final_path="/var/www/$app"
data_path="/home/yunohost.app/$app"
db_name="$app"
db_user="mmuser"
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
yunohost app checkurl "${domain}" -a "$app" \
|| ynh_die "Path not available: ${domain}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_restore_file "$final_path"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_user $db_name $db_pwd
ynh_mysql_connect_as $db_user $db_pwd $db_name < ./db.sql
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
smtp_user="$app"
if ! ynh_system_user_exists "$smtp_user"; then
smtp_password=$(ynh_app_setting_get $app smtp_password)
useradd -M --shell /bin/false -p $(openssl passwd -1 "$smtp_password") "$smtp_user"
fi
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R www-data: $final_path
mkdir -p $data_path
chown -R www-data: $data_path
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Define and install dependencies
# TODO: use ynh_install_app_dependencies once we'll stop supporting Yunohost < 2.6.4
command -v supervisorctl >/dev/null 2>&1 || sudo apt-get install -y supervisor
#=================================================
# RESTORE SUPERVISOR CONF
#=================================================
ynh_restore_file "/etc/supervisor/conf.d/$app.conf"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND START THE APP
#=================================================
sudo service nginx reload
sudo supervisorctl reload

16
test.sh
View file

@ -114,8 +114,18 @@ function test_simple_upgrade() {
function test_simple_backup() { function test_simple_backup() {
echo "--- Running simple backup test ---" echo "--- Running simple backup test ---"
local BACKUP_DIR="$TESTS_DIR/backups" _vagrant_ssh "sudo yunohost backup create --ignore-hooks --apps $APP_NAME $VERBOSE_OPT"
_vagrant_ssh "sudo yunohost backup create --ignore-hooks --no-compress --apps $APP_NAME --output-directory $BACKUP_DIR $VERBOSE_OPT" }
function test_simple_remove() {
echo "--- Running simple remove test ---"
_vagrant_ssh "sudo yunohost app remove $APP_NAME"
}
function test_simple_restore() {
echo "--- Running simple restore test ---"
_vagrant_ssh "sudo yunohost backup list | cut -d ' ' -f 2 > backup_name"
_vagrant_ssh "sudo yunohost backup restore \$(cat backup_name) --force --ignore-hooks --apps $APP_NAME $VERBOSE_OPT"
} }
function test_package_check() { function test_package_check() {
@ -134,5 +144,7 @@ setup
test_simple_install test_simple_install
test_simple_upgrade test_simple_upgrade
test_simple_backup test_simple_backup
test_simple_remove
test_simple_restore
test_package_check test_package_check
teardown teardown