From 6a7e851454c56e70901850d8c45e80f86ea4043f Mon Sep 17 00:00:00 2001 From: Boudewijn Date: Sun, 2 Mar 2025 21:45:15 +0100 Subject: [PATCH] Include restore and upgrade scripts, update change_url --- scripts/change_url | 9 +++++++-- scripts/restore | 43 +++---------------------------------------- scripts/upgrade | 31 ++++++++++++------------------- 3 files changed, 22 insertions(+), 61 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index 890c4d6..0b338b2 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -30,8 +30,13 @@ ynh_config_change_url_nginx #================================================= ## Only the app_url in .env needs to change -sed -i -e 's/$old_doman/new_domain/g' __INSTALL_DIR__/.env -sed -i -e 's/$old_path/new_path/g' __INSTALL_DIR__/.env +sed -i -e 's/$old_domain/new_domain/g' $install_dir/.env +sed -i -e 's/$old_path/new_path/g' $install_dir/.env + +## perhaps a better option, ynh_replace + ynh_store_file_checksum +# ynh_replace --match=$old_domain --replace="$new_domain --file="$install_dir/.env" +# ynh_replace --match=$old_path --replace="$new_path --file="$install_dir/.env" +ynh_store_file_checksum "$install_dir/.env" #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index e2f541a..3e8c0b3 100755 --- a/scripts/restore +++ b/scripts/restore @@ -20,16 +20,6 @@ ynh_restore "$install_dir" ### ownership to all files such as after the ynh_setup_source step chown -R "$app:www-data" "$install_dir" -#================================================= -# RESTORE THE DATA DIRECTORY -#================================================= -ynh_script_progression "Restoring the data directory..." - -ynh_restore "$data_dir" - -### (Same as for install dir) -chown -R "$app:www-data" "$data_dir" - #================================================= # RESTORE THE MYSQL DATABASE #================================================= @@ -44,45 +34,18 @@ ynh_script_progression "Restoring system configurations related to $app..." ### This should be a symetric version of what happens in the install script -ynh_restore "/etc/php/$php_version/fpm/pool.d/$app.conf" - ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_restore "/etc/systemd/system/$app.service" -systemctl enable "$app.service" --quiet -yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log" - -ynh_restore "/etc/logrotate.d/$app" - -ynh_restore "/etc/fail2ban/jail.d/$app.conf" -ynh_restore "/etc/fail2ban/filter.d/$app.conf" -ynh_systemctl --action=restart --service=fail2ban - -#================================================= -# RESTORE VARIOUS FILES -#================================================= - -ynh_restore "/etc/cron.d/$app" -ynh_restore "/etc/$app/" - -### For apps with huge logs, you might want to not backup logs every time: -### The mkdir call is just here in case the log directory was not backed up. -### mkdir -p "/var/log/$app" -### chown $app:www-data "/var/log/$app" -### ynh_restore "/var/log/$app/" || true -### -### For other apps, the simple way is better: -ynh_restore "/var/log/$app/" +#ynh_restore "/etc/fail2ban/jail.d/$app.conf" +#ynh_restore "/etc/fail2ban/filter.d/$app.conf" +#ynh_systemctl --action=restart --service=fail2ban #================================================= # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= ynh_script_progression "Reloading NGINX web server and $app's service..." -### Typically you only have either $app or PHP-FPM but not both at the same time... -ynh_systemctl --service="$app" --action="start" - ynh_systemctl --service="php$php_version-fpm" --action=reload ynh_systemctl --service=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 2401955..bcba06c 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -63,6 +63,13 @@ ynh_setup_source --dest_dir="$install_dir" --full_replace --keep=".env data" ### ownership to all files such as after the ynh_setup_source step chown -R "$app:www-data" "$install_dir" +#================================================= +# TODO - DB migration if applicable +#================================================= +ynh_script_progression "Migrating $app's database to the new data model..." + +## find upstream migration script + #================================================= # UPDATE A CONFIG FILE #================================================= @@ -73,13 +80,14 @@ ynh_script_progression "Updating $app's configuration files..." ### The file will automatically be backed-up if it's found to be manually modified (because ### ynh_config_add keeps track of the file's checksum) -ynh_config_add --template="some_config_file" --destination="$install_dir/some_config_file" +#ynh_config_add --template="some_config_file" --destination="$install_dir/some_config_file" +# there's just the nginx conf and the .env that's still available (--keep above) # FIXME: this should be handled by the core in the future ### You may need to use chmod 600 instead of 400, ### for example if the app is expected to be able to modify its own config -chmod 400 "$install_dir/some_config_file" -chown "$app:$app" "$install_dir/some_config_file" +#chmod 400 "$install_dir/some_config_file" +#chown "$app:$app" "$install_dir/some_config_file" ### For more complex cases where you want to replace stuff using regexes, ### you shoud rely on ynh_replace (which is basically a wrapper for sed) @@ -95,24 +103,9 @@ ynh_script_progression "Upgrading system configurations related to $app..." ### This should be a literal copypaste of what happened in the install's "System configuration" section -ynh_config_add_phpfpm - ynh_config_add_nginx -ynh_config_add_systemd - -yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log" - -ynh_config_add_logrotate - -ynh_config_add_fail2ban --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression "Starting $app's systemd service..." - -ynh_systemctl --service="$app" --action="start" +#ynh_config_add_fail2ban --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" #================================================= # END OF SCRIPT