From 571439b31ba7f05dc55aab401fb1dc4fb90392d2 Mon Sep 17 00:00:00 2001 From: oiseauroch Date: Fri, 17 Mar 2023 09:57:02 +0100 Subject: [PATCH] change hook mechanism --- hooks/conf_regen | 16 ---------------- scripts/backup | 9 +++++++++ scripts/install | 21 +++++++++++++-------- scripts/remove | 8 ++++++++ scripts/restore | 6 +++++- sources/hooks/conf_regen/98-nginx_garage | 12 ++++++++++++ 6 files changed, 47 insertions(+), 25 deletions(-) delete mode 100644 hooks/conf_regen create mode 100644 sources/hooks/conf_regen/98-nginx_garage diff --git a/hooks/conf_regen b/hooks/conf_regen deleted file mode 100644 index d49fbaf..0000000 --- a/hooks/conf_regen +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -source /usr/share/yunohost/helpers - -garage_domains=$(yunohost app list --json | jq '.apps[] | select(.id | test("garage*")) | .domain_path') - -for domain in $garage_domains; -do - domain=${domain//\"/} - if [[ "$domain" =~ "/" ]] - then - domain=${domain/\//} - ynh_replace_special_string --match_string="server_name $domain;" --replace_string="server_name $domain *.$> - fi -done - diff --git a/scripts/backup b/scripts/backup index 7f54697..049b7d3 100755 --- a/scripts/backup +++ b/scripts/backup @@ -66,6 +66,7 @@ ynh_backup --src_path="$final_path" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" + #================================================= # SPECIFIC BACKUP #================================================= @@ -74,6 +75,12 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/logrotate.d/$app" +#================================================= +# BACKUP HOOK +#================================================= + +ynh_backup --src_path="/usr/share/yunohost/hooks/conf_regen/98-nginx_$app" + #================================================= # BACKUP SYSTEMD #================================================= @@ -81,6 +88,8 @@ ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup --src_path="/usr/share/yunohost/hooks/conf_regen/98-nginx_$app" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index cb5e194..53a2c5b 100755 --- a/scripts/install +++ b/scripts/install @@ -201,14 +201,6 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config -#add wildcard subdomain -ynh_replace_special_string --match_string="server_name $domain;" --replace_string="server_name $domain *.$domain;" --target_file="/etc/nginx/conf.d/$domain.conf" -ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.conf" -#================================================= -# SPECIFIC SETUP -#================================================= -# ... -#================================================= #================================================= # ADD A CONFIGURATION @@ -292,6 +284,19 @@ then VIRTUALISATION=true $final_path/umount_disk.sh fi +#================================================= +# ADD REGEN-CONF HOOK +#================================================= +ynh_script_progression --message="adding regen-conf hook..." --weight=1 + + ynh_add_config --template="../sources/hooks/conf_regen/98-nginx_garage" --destination="/usr/share/yunohost/hooks/conf_regen/98-nginx_$app" +#cp -R ../sources/hooks/conf_regen/98-nginx_garage /usr/share/yunohost/hooks/conf_regen/95-nginx_$app + + +ynh_systemd_action --service_name=nginx --action="reload" + + + #================================================= # SETUP SYSTEMD #================================================= diff --git a/scripts/remove b/scripts/remove index 4058727..1e46c73 100755 --- a/scripts/remove +++ b/scripts/remove @@ -96,6 +96,10 @@ ynh_secure_remove --file="$final_path" ynh_script_progression --message="Removing app data directory..." --weight=1 ynh_secure_remove --file="$datadir" +#================================================= +# REMOVE NGINX HOOK +#================================================= + #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -147,6 +151,10 @@ ynh_script_progression --message="Removing the dedicated system user..." --weig # Delete a system user ynh_system_user_delete --username=$app +ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/98-nginx_$app" +yunohost tools regen-conf nginx +ynh_systemd_action --service_name=nginx --action="reload" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index c41fd10..70607ab 100755 --- a/scripts/restore +++ b/scripts/restore @@ -115,7 +115,11 @@ ynh_script_progression --message="Restoring the NGINX web server configuration.. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #add wildcard subdomain -ynh_replace_special_string --match_string="server_name $domain" --replace_string="server_name $domain *.$domain" --target_file="/etc/nginx/conf.d/$domain.conf" + + +ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/98-nginx_$app" +yunohost tools regen-conf nginx +ynh_systemd_action --service_name=nginx --action="reload" #================================================= diff --git a/sources/hooks/conf_regen/98-nginx_garage b/sources/hooks/conf_regen/98-nginx_garage new file mode 100644 index 0000000..a974512 --- /dev/null +++ b/sources/hooks/conf_regen/98-nginx_garage @@ -0,0 +1,12 @@ +#!/bin/bash + +action=$1 +pending_dir=$4 +domain=__DOMAIN__ +app=__APP__ + +[[ "$action" == "pre" ]] || exit 0 +source /usr/share/yunohost/helpers + +ynh_replace_special_string --match_string="server_name $domain" --replace_string="server_name $domain *.$domain" --target_file="/etc/nginx/conf.d/$domain.conf" +ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.conf"