1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/discourse_ynh.git synced 2024-09-03 18:26:18 +02:00
This commit is contained in:
ericgaspar 2021-06-03 18:03:09 +02:00
parent 5ae8db5f95
commit b21ad42e5d
No known key found for this signature in database
GPG key ID: 574F281483054D44
3 changed files with 60 additions and 60 deletions

View file

@ -63,25 +63,25 @@ check_memory_requirements_upgrade() {
} }
ynh_maintenance_mode_ON () { ynh_maintenance_mode_ON () {
# Load value of $path_url and $domain from the config if their not set # Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then if [ -z $path_url ]; then
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get $app path)
fi fi
if [ -z $domain ]; then if [ -z $domain ]; then
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
fi fi
# Create an html to serve as maintenance notice # Create an html to serve as maintenance notice
echo "<!DOCTYPE html> echo "<!DOCTYPE html>
<html> <html>
<head> <head>
<meta http-equiv="refresh" content="3"> <meta http-equiv="refresh" content="3">
<title>Your app $app is currently under maintenance!</title> <title>Your app $app is currently under maintenance!</title>
<style> <style>
body { body {
width: 70em; width: 70em;
margin: 0 auto; margin: 0 auto;
} }
</style> </style>
</head> </head>
<body> <body>
@ -92,8 +92,8 @@ ynh_maintenance_mode_ON () {
</body> </body>
</html>" > "/var/www/html/maintenance.$app.html" </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. # 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_url}_maintenance and fall on the maintenance notice echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice
rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect; rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect;
# Use another location, to not be in conflict with the original config file # Use another location, to not be in conflict with the original config file
location ${path_url}_maintenance/ { location ${path_url}_maintenance/ {
@ -105,38 +105,38 @@ try_files maintenance.$app.html =503;
include conf.d/yunohost_panel.conf.inc; include conf.d/yunohost_panel.conf.inc;
}" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" }" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
# The current config file will redirect all requests to the root of the app. # 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: # To keep the full path, we can use the following rewrite rule:
# rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect; # rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect;
# The difference will be in the $1 at the end, which keep the following queries. # 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. # 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. # 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. # 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 () { ynh_maintenance_mode_OFF () {
# Load value of $path_url and $domain from the config if their not set # Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then if [ -z $path_url ]; then
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get $app path)
fi fi
if [ -z $domain ]; then if [ -z $domain ]; then
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
fi fi
# Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app. # Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app.
echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
systemctl reload nginx systemctl reload nginx
# Sleep 4 seconds to let the browser reload the pages and redirect the user to the app. # Sleep 4 seconds to let the browser reload the pages and redirect the user to the app.
sleep 4 sleep 4
# Then remove the temporary files used for the maintenance. # Then remove the temporary files used for the maintenance.
rm "/var/www/html/maintenance.$app.html" rm "/var/www/html/maintenance.$app.html"
rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
systemctl reload nginx systemctl reload nginx
} }
#================================================= #=================================================
@ -463,27 +463,27 @@ ynh_cleanup_ruby () {
# usage: ynh_redis_get_free_db # usage: ynh_redis_get_free_db
# | returns: the database number to use # | returns: the database number to use
ynh_redis_get_free_db() { ynh_redis_get_free_db() {
local result max db local result max db
result="$(redis-cli INFO keyspace)" result="$(redis-cli INFO keyspace)"
# get the num # get the num
max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+") max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+")
db=0 db=0
# default Debian setting is 15 databases # default Debian setting is 15 databases
for i in $(seq 0 "$max") for i in $(seq 0 "$max")
do do
if ! echo "$result" | grep -q "db$i" if ! echo "$result" | grep -q "db$i"
then then
db=$i db=$i
break 1 break 1
fi fi
db=-1 db=-1
done done
test "$db" -eq -1 && ynh_die --message="No available Redis databases..." test "$db" -eq -1 && ynh_die --message="No available Redis databases..."
echo "$db" echo "$db"
} }
# Create a master password and set up global settings # Create a master password and set up global settings
@ -492,6 +492,6 @@ ynh_redis_get_free_db() {
# usage: ynh_redis_remove_db database # usage: ynh_redis_remove_db database
# | arg: database - the database to erase # | arg: database - the database to erase
ynh_redis_remove_db() { ynh_redis_remove_db() {
local db=$1 local db=$1
redis-cli -n "$db" flushall redis-cli -n "$db" flushall
} }

View file

@ -169,7 +169,7 @@ pushd "$final_path"
# Install bundler, a gems installer # Install bundler, a gems installer
ynh_gem install bundler ynh_gem install bundler
# Install without documentation # Install without documentation
exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc"
popd popd
# Specific actions on ARM architecture # Specific actions on ARM architecture

View file

@ -240,7 +240,7 @@ then
# Install bundler, a gems installer # Install bundler, a gems installer
ynh_gem install bundler ynh_gem install bundler
# Install without documentation # Install without documentation
exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc"
popd popd
# Specific actions on ARM architecture # Specific actions on ARM architecture