1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/discourse_ynh.git synced 2024-09-03 18:26:18 +02:00

Tabs to spaces

This commit is contained in:
Félix Piédallu 2024-08-29 12:52:07 +02:00
parent 5dc2e9f19c
commit 19ad49c184

View file

@ -17,56 +17,56 @@ libjemalloc="$(ldconfig -p | grep libjemalloc | awk 'END {print $NF}')"
# Returns true if a swap partition is enabled, false otherwise # Returns true if a swap partition is enabled, false otherwise
# usage: is_swap_present # usage: is_swap_present
is_swap_present() { is_swap_present() {
[ $(awk '/^SwapTotal:/{print $2}' /proc/meminfo) -gt 0 ] [ $(awk '/^SwapTotal:/{print $2}' /proc/meminfo) -gt 0 ]
} }
# Returns true if swappiness higher than 10 # Returns true if swappiness higher than 10
# usage: is_swappiness_sufficient # usage: is_swappiness_sufficient
is_swappiness_sufficient() { is_swappiness_sufficient() {
[ $(cat /proc/sys/vm/swappiness) -gt 10 ] [ $(cat /proc/sys/vm/swappiness) -gt 10 ]
} }
# Returns true if specified free memory is available (RAM + swap) # Returns true if specified free memory is available (RAM + swap)
# usage: is_memory_available MEMORY (in bytes) # usage: is_memory_available MEMORY (in bytes)
is_memory_available() { is_memory_available() {
local needed_memory=$1 local needed_memory=$1
local freemem="$(awk '/^MemAvailable:/{print $2}' /proc/meminfo)" local freemem="$(awk '/^MemAvailable:/{print $2}' /proc/meminfo)"
local freeswap="$(awk '/^SwapFree:/{print $2}' /proc/meminfo)" local freeswap="$(awk '/^SwapFree:/{print $2}' /proc/meminfo)"
[ $(($freemem+$freeswap)) -gt $needed_memory ] [ $(($freemem+$freeswap)) -gt $needed_memory ]
} }
# Checks discourse install memory requirements # Checks discourse install memory requirements
# terminates installation if requirements not met # terminates installation if requirements not met
check_memory_requirements() { check_memory_requirements() {
if ! is_swap_present ; then if ! is_swap_present ; then
ynh_print_warn --message="You must have a swap partition in order to install and use this application" ynh_print_warn --message="You must have a swap partition in order to install and use this application"
elif ! is_swappiness_sufficient ; then elif ! is_swappiness_sufficient ; then
ynh_print_warn --message="Your swappiness must be higher than 10; please see https://en.wikipedia.org/wiki/Swappiness" ynh_print_warn --message="Your swappiness must be higher than 10; please see https://en.wikipedia.org/wiki/Swappiness"
elif ! is_memory_available 1000000 ; then elif ! is_memory_available 1000000 ; then
ynh_print_warn --message="You must have a minimum of 1Gb available memory (RAM+swap) for the installation" ynh_print_warn --message="You must have a minimum of 1Gb available memory (RAM+swap) for the installation"
fi fi
} }
# Checks discourse upgrade memory requirements # Checks discourse upgrade memory requirements
# Less requirements as the software is already installed and running # Less requirements as the software is already installed and running
# terminates upgrade if requirements not met # terminates upgrade if requirements not met
check_memory_requirements_upgrade() { check_memory_requirements_upgrade() {
if ! is_memory_available 400000 ; then if ! is_memory_available 400000 ; then
ynh_die --message="You must have a minimum of 400Mb available memory (RAM+swap) for the upgrade" ynh_die --message="You must have a minimum of 400Mb available memory (RAM+swap) for the upgrade"
fi fi
} }
ynh_maintenance_mode_ON () { ynh_maintenance_mode_ON () {
# 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>
@ -77,8 +77,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}_maintenance and fall on the maintenance notice echo "# All request to the app will be redirected to ${path}_maintenance and fall on the maintenance notice
rewrite ^${path}/(.*)$ ${path}_maintenance/? redirect; rewrite ^${path}/(.*)$ ${path}_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}_maintenance/ { location ${path}_maintenance/ {
@ -90,30 +90,30 @@ 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}/(.*)$ ${path}_maintenance/\$1? redirect; # rewrite ^${path}/(.*)$ ${path}_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 () {
# Rewrite the nginx config file to redirect from ${path}_maintenance to the real url of the app. # 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" echo "rewrite ^${path}_maintenance/(.*)$ ${path}/\$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
} }
#================================================= #=================================================