mirror of
https://github.com/YunoHost-Apps/monica_ynh.git
synced 2024-09-03 19:46:23 +02:00
Fixed backup and restore,some fix in instal,remove,upgrade
This commit is contained in:
parent
29d10c00bd
commit
d7956d9bd7
5 changed files with 78 additions and 75 deletions
|
@ -2,13 +2,6 @@
|
|||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
@ -21,6 +14,13 @@ fi
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
@ -30,11 +30,7 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
||||
|
||||
# The parameter $1 is the backup directory location which will be compressed afterward
|
||||
backup_dir=$1/apps/container-$app
|
||||
sudo mkdir -p $backup_dir
|
||||
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
|
@ -42,23 +38,29 @@ sudo mkdir -p $backup_dir
|
|||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_backup "$final_path" "${backup_dir}/$final_path"
|
||||
ynh_backup "$final_path"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
ynh_mysql_dump_db "$db_name" > db.sql
|
||||
ynh_backup "db.sql" "${backup_dir}/db.sql"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/php/7.1/fpm/pool.d/$app.conf"
|
||||
ynh_backup "/etc/php/7.1/fpm/conf.d/20-$app.ini"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE CRON FILE
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/cron.d/$app" "${backup_dir}/etc/cron.d/$app"
|
||||
ynh_backup "/etc/cron.d/$app"
|
||||
|
|
|
@ -145,9 +145,8 @@ cd $final_path && sudo /usr/bin/php7.1 artisan -q setup:production --force
|
|||
|
||||
|
||||
# create a cronjob to run the scheduler
|
||||
echo "* * * * * sudo $app /usr/bin/php7.1 $final_path/artisan schedule:run" > /tmp/cron$app
|
||||
echo "* * * * * -u $app /usr/bin/php7.1 $final_path/artisan schedule:run" > /tmp/cron$app
|
||||
sudo mv /tmp/cron$app /etc/cron.d/$app
|
||||
sudo chown root /etc/cron.d/$app
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
|
@ -158,6 +157,13 @@ sudo chown root /etc/cron.d/$app
|
|||
# Set permissions to app files
|
||||
chown -R $app: $final_path
|
||||
|
||||
#=================================================
|
||||
# STORE THE CHECKSUM OF THE CONFIG FILE
|
||||
#=================================================
|
||||
|
||||
# Calculate and store the config file checksum into the app settings
|
||||
ynh_store_file_checksum "$final_path/.env"
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
|
@ -176,5 +182,5 @@ fi
|
|||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
systemctl reload php7.1-fpm
|
||||
systemctl reload nginx
|
||||
|
|
|
@ -17,6 +17,8 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
db_user=$db_name
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
|
@ -32,14 +34,14 @@ ynh_remove_app_dependencies
|
|||
#=================================================
|
||||
|
||||
# Remove a database if it exists, along with the associated user
|
||||
ynh_mysql_remove_db $db_name $db_name
|
||||
ynh_mysql_remove_db $db_user $db_name
|
||||
|
||||
#=================================================
|
||||
# REMOVE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove "/var/www/$app"
|
||||
ynh_secure_remove "$final_path"
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
|
|
|
@ -2,22 +2,6 @@
|
|||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
|
||||
yunohost app checkurl "${domain}${path_url}" -a "$app" \
|
||||
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||
test ! -d $final_path \
|
||||
|| ynh_die "There is already a directory: $final_path "
|
||||
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
@ -30,6 +14,13 @@ fi
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
@ -41,8 +32,25 @@ path_url=$(ynh_app_setting_get $app path)
|
|||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
|
||||
#=================================================
|
||||
# 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 "
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# REINSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
# Define and install dependencies
|
||||
ynh_install_php7
|
||||
ynh_install_nodejs 9
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
@ -76,24 +84,18 @@ ynh_system_user_create $app
|
|||
# REINSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
ynh_install_php7
|
||||
ynh_install_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-bcmath
|
||||
|
||||
ynh_install_nodejs 6.10.3
|
||||
|
||||
init_composer $final_path
|
||||
|
||||
cd $final_path && sudo_path npm install -g npm@4 pnpm
|
||||
cd $final_path && sudo_path pnpm install
|
||||
cd $final_path && sudo_path pnpm install -g bower gulp
|
||||
cd $final_path && sudo_path bower install -f --allow-root
|
||||
# Run migration
|
||||
cd $final_path && sudo /usr/bin/php7.1 artisan migrate --force
|
||||
|
||||
|
||||
#=================================================
|
||||
# RESTORE USER RIGHTS
|
||||
#=================================================
|
||||
|
||||
# Restore permissions on app files
|
||||
chown -R www-data: $final_path
|
||||
chown -R $app: $final_path
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE CRON FILE
|
||||
|
@ -107,5 +109,5 @@ ynh_restore_file "/etc/cron.d/$app"
|
|||
# RELOAD NGINX AND PHP-FPM
|
||||
#=================================================
|
||||
|
||||
systemctl reload php5-fpm
|
||||
systemctl reload php7.1-fpm
|
||||
systemctl reload nginx
|
||||
|
|
|
@ -9,13 +9,6 @@
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
@ -45,6 +38,18 @@ if [ -z $db_name ]; then # If db_name doesn't exist, create it
|
|||
db_name=$(ynh_sanitize_dbid $app)
|
||||
ynh_app_setting_set $app db_name $db_name
|
||||
fi
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# CHECK THE PATH
|
||||
|
@ -58,9 +63,15 @@ path_url=$(ynh_normalize_url_path $path_url)
|
|||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
# Create a temporary directory
|
||||
tmpdir="$(mktemp -d)"
|
||||
cp -a "$final_path/.env" "$tmpdir/.env"
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source "$final_path"
|
||||
cp -a "$tmpdir/.env" "$final_path/.env"
|
||||
#remove tmp dir
|
||||
sudo rm -Rf "$tmpdir"
|
||||
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
|
@ -80,8 +91,6 @@ ynh_system_user_create $app
|
|||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
# ...
|
||||
#=================================================
|
||||
|
||||
# install new dependencies
|
||||
ynh_install_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-bcmath
|
||||
|
@ -93,24 +102,6 @@ ynh_install_app_dependencies php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xm
|
|||
# Create a dedicated php-fpm7.1 config
|
||||
ynh_add_fpm7.1_config
|
||||
|
||||
|
||||
# create a user
|
||||
email=$(ynh_user_get_info $admin 'mail')
|
||||
|
||||
# setup application config
|
||||
sudo cp ../conf/.env $final_path/.env
|
||||
|
||||
db_name=$(ynh_sanitize_dbid $app)
|
||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
||||
sudo sed -i "s/yunouser/$db_name/g" $final_path/.env
|
||||
sudo sed -i "s/yunopass/$db_pwd/g" $final_path/.env
|
||||
sudo sed -i "s/yunobase/$db_name/g" $final_path/.env
|
||||
sudo sed -i "s/yunomail/$email/g" $final_path/.env
|
||||
sudo sed -i "s/yunodomain/$domain/g" $final_path/.env
|
||||
sudo sed -i "s/language/$language/g" $final_path/.env
|
||||
|
||||
exec_composer "$final_path" update --quiet --no-dev --prefer-dist
|
||||
|
||||
# setup application config
|
||||
cd $final_path && sudo /usr/bin/php7.1 artisan migrate --force
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue