Include restore and upgrade scripts, update change_url

This commit is contained in:
Boudewijn 2025-03-02 21:45:15 +01:00
parent d41c3be841
commit 6a7e851454
3 changed files with 22 additions and 61 deletions

View file

@ -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

View file

@ -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

View file

@ -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