diff --git a/scripts/_common.sh b/scripts/_common.sh index 24b3ebe..fb916bc 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -55,82 +55,82 @@ check_memory_requirements_upgrade() { fi } -# ynh_maintenance_mode_ON () { -# # Load value of $path and $domain from the config if their not set -# if [ -z $path ]; then -# #REMOVEME? path=$(ynh_app_setting_get $app path) -# fi -# if [ -z $domain ]; then -# #REMOVEME? domain=$(ynh_app_setting_get $app domain) -# fi +ynh_maintenance_mode_ON () { + # Load value of $path and $domain from the config if their not set + if [ -z $path ]; then +#REMOVEME? path=$(ynh_app_setting_get $app path) + fi + if [ -z $domain ]; then +#REMOVEME? domain=$(ynh_app_setting_get $app domain) + fi -# # Create an html to serve as maintenance notice -# echo " -# -#
-# -#This app has been put under maintenance by your administrator at $(date)
-#Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.
+ # Create an html to serve as maintenance notice + echo " + + + +This app has been put under maintenance by your administrator at $(date)
+Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.
-# -# " > "/var/www/html/maintenance.$app.html" + +" > "/var/www/html/maintenance.$app.html" -# # Create a new nginx config file to redirect all access to the app to the maintenance notice instead. -# echo "# All request to the app will be redirected to ${path}_maintenance and fall on the maintenance notice -# rewrite ^${path}/(.*)$ ${path}_maintenance/? redirect; -# # Use another location, to not be in conflict with the original config file -# location ${path}_maintenance/ { -# alias /var/www/html/ ; + # Create a new nginx config file to redirect all access to the app to the maintenance notice instead. + echo "# All request to the app will be redirected to ${path}_maintenance and fall on the maintenance notice +rewrite ^${path}/(.*)$ ${path}_maintenance/? redirect; +# Use another location, to not be in conflict with the original config file +location ${path}_maintenance/ { +alias /var/www/html/ ; -# try_files maintenance.$app.html =503; +try_files maintenance.$app.html =503; -# # Include SSOWAT user panel. -# include conf.d/yunohost_panel.conf.inc; -# }" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" +# Include SSOWAT user panel. +include conf.d/yunohost_panel.conf.inc; +}" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" -# # The current config file will redirect all requests to the root of the app. -# # To keep the full path, we can use the following rewrite rule: -# # rewrite ^${path}/(.*)$ ${path}_maintenance/\$1? redirect; -# # The difference will be in the $1 at the end, which keep the following queries. -# # But, if it works perfectly for a html request, there's an issue with any php files. -# # This files are treated as simple files, and will be downloaded by the browser. -# # Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was. + # The current config file will redirect all requests to the root of the app. + # To keep the full path, we can use the following rewrite rule: + # rewrite ^${path}/(.*)$ ${path}_maintenance/\$1? redirect; + # The difference will be in the $1 at the end, which keep the following queries. + # But, if it works perfectly for a html request, there's an issue with any php files. + # This files are treated as simple files, and will be downloaded by the browser. + # Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was. -# systemctl reload nginx -# } + systemctl reload nginx +} -# ynh_maintenance_mode_OFF () { -# # Load value of $path and $domain from the config if their not set -# if [ -z $path ]; then -# #REMOVEME? path=$(ynh_app_setting_get $app path) -# fi -# if [ -z $domain ]; then -# #REMOVEME? domain=$(ynh_app_setting_get $app domain) -# fi +ynh_maintenance_mode_OFF () { + # Load value of $path and $domain from the config if their not set + if [ -z $path ]; then +#REMOVEME? path=$(ynh_app_setting_get $app path) + fi + if [ -z $domain ]; then +#REMOVEME? domain=$(ynh_app_setting_get $app domain) + fi -# # Rewrite the nginx config file to redirect from ${path}_maintenance to the real url of the app. -# echo "rewrite ^${path}_maintenance/(.*)$ ${path}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" -# systemctl reload nginx + # Rewrite the nginx config file to redirect from ${path}_maintenance to the real url of the app. + echo "rewrite ^${path}_maintenance/(.*)$ ${path}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" + systemctl reload nginx -# # Sleep 4 seconds to let the browser reload the pages and redirect the user to the app. -# sleep 4 + # Sleep 4 seconds to let the browser reload the pages and redirect the user to the app. + sleep 4 -# # Then remove the temporary files used for the maintenance. -# rm "/var/www/html/maintenance.$app.html" -# rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" + # Then remove the temporary files used for the maintenance. + rm "/var/www/html/maintenance.$app.html" + rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" -# systemctl reload nginx -# } + systemctl reload nginx +} #================================================= # EXPERIMENTAL HELPERS