magikcypress 8 лет назад
Родитель
Сommit
4598396ccd
2 измененных файлов с 42 добавлено и 45 удалено
  1. 16 18
      scripts/backup
  2. 26 27
      scripts/remove

+ 16 - 18
scripts/backup

@@ -3,30 +3,28 @@
 # Exit on command errors and treat unset variables as an error
 set -eu
 
-# The parameter $1 is the backup directory location dedicated to the app
-backup_dir=$1
-
-# The parameter $2 is theid of the app instance
-app=$2
+# Get multi-instances specific variables
+app=$YNH_APP_INSTANCE_NAME
 
 # Source app helpers
 source /usr/share/yunohost/helpers
 
-domain=$(ynh_app_setting_get $app domain)
-final_path=$(ynh_app_setting_get $app final_path)
+# Retrieve app settings
+domain=$(ynh_app_setting_get "$app" domain)
+with_mysql=$(ynh_app_setting_get "$app" with_mysql)
 
 # Copy the app files
-sudo mkdir -p ${backup_dir}/var/www
-sudo cp -a $final_path "${backup_dir}/var/www/$app"
-
-# Copy the conf files
-sudo mkdir -p "${backup_dir}/conf"
-sudo cp -a /etc/nginx/conf.d/$domain.d/$app.conf "${backup_dir}/conf/nginx.conf"
+final_path="/var/www/${app}"
+ynh_backup "$final_path" "sources" 1
 
-# Copy dedicated php-fpm process to backup folder
-sudo cp -a /etc/php5/fpm/pool.d/$app.conf "${backup_dir}/conf/php-fpm.conf"
-sudo cp -a /etc/php5/fpm/conf.d/20-$app.ini "${backup_dir}/conf/php-fpm.ini"
+# Copy the nginx conf files
+ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
+# Copy the php-fpm conf files
+ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf"
+ynh_backup "/etc/php5/fpm/conf.d/20-${app}.ini" "php-fpm.ini"
 
 # Backup db
-root_pwd=$(sudo cat /etc/yunohost/mysql)
-sudo su -c "mysqldump -u root -p$root_pwd --no-create-db $app > ${backup_dir}/db.sql"
+if [[ $with_mysql -eq 1 ]]; then
+	root_pwd=$(sudo cat /etc/yunohost/mysql)
+	sudo su -c "mysqldump -u root -p$root_pwd --no-create-db $app > ./db.sql"
+fi

+ 26 - 27
scripts/remove

@@ -3,33 +3,32 @@
 # Exit on command errors and treat unset variables as an error
 set -u
 
-source .fonctions	# Charge les fonctions génériques habituellement utilisées dans le script
-
-# Source app helpers
-source /usr/share/yunohost/helpers
-
-#=================================================
-# LOAD SETTINGS
-#=================================================
-
+# Get multi-instances specific variables
 app=$YNH_APP_INSTANCE_NAME
 
-domain=$(ynh_app_setting_get $app domain)
-db_name=$(ynh_app_setting_get $app db_name)
-
-#=================================================
-# REMOVE THE SQL BDD
-#=================================================
-
-ynh_mysql_remove_db $db_name $db_name	# Suppression de la base de donnée et de l'utilisateur associé.
-
-SECURE_REMOVE '/var/www/$app'	# Suppression du dossier de l'application
-
-REMOVE_NGINX_CONF	# Suppression de la configuration nginx
-
-REMOVE_FPM_CONF	# Suppression de la configuration du pool php-fpm
-
-# Régénère la configuration de SSOwat
-sudo yunohost app ssowatconf
+# Source app helpers
+. /usr/share/yunohost/helpers
+
+# Retrieve app settings
+domain=$(ynh_app_setting_get "$app" domain)
+with_mysql=$(ynh_app_setting_get "$app" with_mysql)
+
+# Drop MySQL database and user as needed
+if [[ $with_mysql -eq 1 ]]; then
+    dbname=$app
+    dbuser=$app
+    dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
+    ynh_mysql_drop_db $dbname || true
+    ynh_mysql_drop_user $dbuser || true
+fi
+
+# Delete app directory and configurations
+sudo rm -rf "/var/www/${app}"
+sudo rm -f "/etc/php5/fpm/pool.d/${app}.conf"
+sudo rm -f "/etc/php5/fpm/conf.d/20-${app}.ini"
+[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
+
+# Reload services
+sudo service php5-fpm restart || true
+sudo service nginx reload || true
 
-echo -e "\e[0m"	# Restore normal color