Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers: Further simplify the change url helper #1746

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions helpers/nginx
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,22 @@ ynh_remove_nginx_config() {
}


# Move / regen the nginx config in a change url context
# Regen the nginx config in a change url context
#
# usage: ynh_change_url_nginx_config
#
# Requires YunoHost version 11.1.9 or higher.
ynh_change_url_nginx_config() {
local old_nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
local new_nginx_conf_path=/etc/nginx/conf.d/$new_domain.d/$app.conf

# Change the path in the NGINX config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$old_nginx_conf_path"
# Set global variables for NGINX helper
domain="$old_domain"
path="$new_path"
path_url="$new_path"
# Create a dedicated NGINX config
ynh_add_nginx_config
fi
# Make a backup of the original NGINX config file if manually modified
# (nb: this is possibly different from the same instruction called by
# ynh_add_config inside ynh_add_nginx_config because the path may have
# changed if we're changing the domain too...)
local old_nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
ynh_backup_if_checksum_is_different --file="$old_nginx_conf_path"
ynh_delete_file_checksum --file="$old_nginx_conf_path"
ynh_secure_remove --file="$old_nginx_conf_path"

# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
ynh_delete_file_checksum --file="$old_nginx_conf_path"
mv "$old_nginx_conf_path" "$new_nginx_conf_path"
ynh_store_file_checksum --file="$new_nginx_conf_path"
fi
ynh_systemd_action --service_name=nginx --action=reload
# Regen the nginx conf
ynh_add_nginx_config
}

2 changes: 2 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ def app_change_url(operation_logger, app, domain, path):
env_dict["old_path"] = old_path
env_dict["new_domain"] = domain
env_dict["new_path"] = path
env_dict["domain"] = domain
env_dict["path"] = path
env_dict["change_path"] = "1" if old_path != path else "0"
env_dict["change_domain"] = "1" if old_domain != domain else "0"

Expand Down