From 80242a8edc8e2529ffe9c9d9fd683d9e0921f2b2 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Fri, 28 Jul 2017 19:11:28 +0200 Subject: [PATCH] New helpers ynh_add_nginx_config and ynh_remove_nginx_config (#285) * New helpers ynh_add_nginx_config and ynh_remove_nginx_config Standard configuration of nginx Use local files stored in conf/, so it's still possible to use a specific config * ynh_substitute_char was renamed ynh_replace_string * ynh_compare_checksum_config -> ynh_backup_if_checksum_is_different * Upgrade helpers * Add some description of which keywords are replaced by which variable --- data/helpers.d/backend | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/data/helpers.d/backend b/data/helpers.d/backend index edd8ad7f4..a6b14fc84 100644 --- a/data/helpers.d/backend +++ b/data/helpers.d/backend @@ -62,6 +62,54 @@ ynh_remove_logrotate () { fi } +# Create a dedicated nginx config +# +# This will use a template in ../conf/nginx.conf +# and will replace the following keywords with +# global variables that should be defined before calling +# this helper : +# +# __PATH__ by $path_url +# __DOMAIN__ by $domain +# __PORT__ by $port +# __NAME__ by $app +# __FINALPATH__ by $final_path +# +# usage: ynh_add_nginx_config +ynh_add_nginx_config () { + finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_backup_if_checksum_is_different "$finalnginxconf" + sudo cp ../conf/nginx.conf "$finalnginxconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${path_url:-}"; then + ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf" + fi + if test -n "${domain:-}"; then + ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf" + fi + if test -n "${port:-}"; then + ynh_replace_string "__PORT__" "$port" "$finalnginxconf" + fi + if test -n "${app:-}"; then + ynh_replace_string "__NAME__" "$app" "$finalnginxconf" + fi + if test -n "${final_path:-}"; then + ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf" + fi + ynh_store_file_checksum "$finalnginxconf" + + sudo systemctl reload nginx +} + +# Remove the dedicated nginx config +# +# usage: ynh_remove_nginx_config +ynh_remove_nginx_config () { + ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf" + sudo systemctl reload nginx + # Create a dedicated php-fpm config # # usage: ynh_add_fpm_config