1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/coin_ynh.git synced 2024-09-03 18:16:26 +02:00

[wip] Backup, upgrade, restore

This commit is contained in:
ljf 2019-08-24 17:35:13 +02:00
parent cc47c58e22
commit df2b88bcfb
3 changed files with 76 additions and 90 deletions

View file

@ -56,7 +56,7 @@ ynh_script_progression --message="Backing up nginx web server configuration..."
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BACKUP THE MYSQL DATABASE # BACKUP THE PSQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Backing up the PSQL database..." --time --weight=1 ynh_script_progression --message="Backing up the PSQL database..." --time --weight=1

View file

@ -26,13 +26,19 @@ ynh_abort_if_errors
#================================================= #=================================================
ynh_script_progression --message="Loading settings..." --time --weight=1 ynh_script_progression --message="Loading settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME export app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) export domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) export path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) export admin=$(ynh_app_setting_get --app=$app --key=admin)
db_name=$(ynh_app_setting_get --app=$app --key=db_name) export email=$(ynh_app_setting_get --app=$app --key=email)
db_user=$db_name export isp_name=$(ynh_app_setting_get --app=$app --key=isp_name)
export isp_site=$(ynh_app_setting_get --app=$app --key=isp_site)
export secret=$(ynh_app_setting_get --app=$app --key=secret)
export is_public=$(ynh_app_setting_get --app=$app --key=is_public)
export final_path=$(ynh_app_setting_get --app=$app --key=final_path)
export db_name=$(ynh_app_setting_get --app=$app --key=db_name)
export db_user=$db_name
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
@ -74,21 +80,6 @@ ynh_system_user_create --username=$app
# Restore permissions on app files # Restore permissions on app files
chown -R root: $final_path chown -R root: $final_path
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf"
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the fail2ban configuration..." --time --weight=1
ynh_restore_file "/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file "/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
#================================================= #=================================================
@ -100,13 +91,15 @@ ynh_script_progression --message="Reinstalling dependencies..." --time --weight=
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
# RESTORE THE MYSQL DATABASE # RESTORE THE PSQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring the MySQL database..." --time --weight=1 ynh_script_progression --message="Restoring the MySQL database..." --time --weight=1
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) ynh_psql_test_if_first_run
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
@ -129,26 +122,21 @@ ynh_script_progression --message="Starting a systemd service..." --time --weight
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# RESTORE THE CRON FILE
#=================================================
ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================
# CONFIGURE LOG DIR
#================================================= #================================================
# RESTORE THE LOGROTATE CONFIGURATION mkdir -p /var/log/$app
#================================================= chown -R $app /var/log/$app
chgrp -R www-data /var/log/$app
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1 ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
ynh_systemd_action --service_name=php7.0-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================

View file

@ -14,15 +14,18 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1 ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME export app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) export domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) export path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin) export admin=$(ynh_app_setting_get --app=$app --key=admin)
is_public=$(ynh_app_setting_get --app=$app --key=is_public) export email=$(ynh_app_setting_get --app=$app --key=email)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) export isp_name=$(ynh_app_setting_get --app=$app --key=isp_name)
language=$(ynh_app_setting_get --app=$app --key=language) export isp_site=$(ynh_app_setting_get --app=$app --key=isp_site)
db_name=$(ynh_app_setting_get --app=$app --key=db_name) export secret=$(ynh_app_setting_get --app=$app --key=secret)
export is_public=$(ynh_app_setting_get --app=$app --key=is_public)
export final_path=$(ynh_app_setting_get --app=$app --key=final_path)
export db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
@ -58,7 +61,7 @@ fi
# If final_path doesn't exist, create it # If final_path doesn't exist, create it
if [ -z "$final_path" ]; then if [ -z "$final_path" ]; then
final_path=/var/www/$app final_path=/opt/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi fi
@ -76,18 +79,6 @@ ynh_clean_setup () {
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
# N.B. : this is for app installations before YunoHost 2.7
# where this value might be something like /foo/ or foo/
# instead of /foo ....
# If nobody installed your app before 2.7, then you may
# safely remove this line
path_url=$(ynh_normalize_url_path --path_url=$path_url)
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
#================================================= #=================================================
@ -132,37 +123,52 @@ ynh_script_progression --message="Making sure dedicated system user exists..." -
# Create a dedicated user (if not existing) # Create a dedicated user (if not existing)
ynh_system_user_create --username=$app ynh_system_user_create --username=$app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1
# Create a dedicated php-fpm config
ynh_add_fpm_config
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
#================================================= #=================================================
# ... # CONFIGURATION DJANGO
#================================================= #=================================================
#================================================= export prefix="${path_url#"/"}/"
# STORE THE CONFIG FILE CHECKSUM prefix=${prefix%"/"}
#================================================= ynh_backup_if_checksum_is_different --file="$final_path/app/settings_local.py"
ynh_render_template ../conf/local.py.j2 "$final_path/app/setings_local.py"
ynh_store_file_checksum --file="$final_path/app/settings_local.py"
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. virtualenv "$final_path/venv"
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. (
ynh_backup_if_checksum_is_different --file="$final_path/CONFIG_FILE" set +o nounset
# Recalculate and store the checksum of the file for the next upgrade. source "${final_path}/venv/bin/activate"
ynh_store_file_checksum --file="$final_path/CONFIG_FILE" set -o nounset
#=================================================
# PYTHON DEPENDENCIES
#=================================================
echo "django-auth-ldap<1.4" >> $final_path/requirements.txt
$final_path/venv/bin/pip install -r $final_path/requirements.txt
#=================================================
# MIGRATE DB
#=================================================
$final_path/venv/bin/python manage.py migrate --noinput
#=================================================
# COLLECT FILES
#=================================================
$final_path/venv/bin/python manage.py collectstatic --noinput
)
#================================================= #=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
# Use logrotate to manage app-specific logfile(s) #================================================
ynh_use_logrotate --non-append # UPDATE GUNICORN
#================================================
ynh_backup_if_checksum_is_different --file="$final_path/gunicorn_config.py"
ynh_replace_string --match_string="__YNH_APP_INSTANCE_NAME__" --replace_string="$app" --target_file="../conf/gunicorn_config.py"
cp -f ../conf/gunicorn_config.py $final_path/
ynh_store_file_checksum --file="$final_path/gunicorn_config.py"
chown $app:www-data $final_path/gunicorn_config.py
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
@ -174,14 +180,6 @@ ynh_add_systemd_config
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#=================================================
# UPGRADE FAIL2BAN
#=================================================
ynh_script_progression --message="Reconfiguring fail2ban..." --time --weight=1
# Create a dedicated fail2ban config
ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
#================================================= #=================================================
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================