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

Check memory requirements to prevent install/upgrade/restore processes from being killed

This commit is contained in:
Jimmy Monin 2018-04-30 18:53:20 +02:00
parent 48ac081464
commit 4fdbfe333c
4 changed files with 51 additions and 1 deletions

View file

@ -27,6 +27,47 @@ exec_as() {
fi fi
} }
# Returns true if a swap partition is enabled, false otherwise
# usage: is_swap_present
is_swap_present() {
[ $(awk '/^SwapTotal:/{print $2}' /proc/meminfo) -gt 0 ]
}
# Returns true if swappiness higher than 50
# usage: is_swappiness_sufficient
is_swappiness_sufficient() {
[ $(cat /proc/sys/vm/swappiness) -gt 50 ]
}
# Returns true if specified free memory is available (RAM + swap)
# usage: is_memory_available MEMORY (in bytes)
is_memory_available() {
local needed_memory=$1
local freemem="$(awk '/^MemAvailable:/{print $2}' /proc/meminfo)"
local freeswap="$(awk '/^SwapFree:/{print $2}' /proc/meminfo)"
[ $(($freemem+$freeswap)) -gt $needed_memory ]
}
# Checks discourse install memory requirements
# terminates installation if requirements not met
check_memory_requirements() {
if ! is_swap_present ; then
ynh_die "You must have a swap partition in order to install and use this application"
elif ! is_swappiness_sufficient ; then
ynh_die "Your swappiness must be higher than 50; please see https://en.wikipedia.org/wiki/Swappiness"
elif ! is_memory_available 1000000 ; then
ynh_die "You must have a minimum of 1Gb available memory (RAM+swap) for the installation"
fi
}
# Checks discourse upgrade memory requirements
# Less requirements as the software is already installed and running
# terminates upgrade if requirements not met
check_memory_requirements_upgrade() {
if ! is_memory_available 400000 ; then
ynh_die "You must have a minimum of 400Mb available memory (RAM+swap) for the upgrade"
fi
}
#================================================= #=================================================
# POSTGRES HELPERS # POSTGRES HELPERS
#================================================= #=================================================

View file

@ -15,7 +15,7 @@ source _common.sh
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
# Nettoyage des résidus d'installation non pris en charge par le script remove. # Nettoyage des résidus d'installation non pris en charge par le script remove.
ynh_clean_check_starting_systemd ynh_clean_check_starting_systemd
} }
ynh_abort_if_errors # Stop script if an error is detected ynh_abort_if_errors # Stop script if an error is detected
@ -47,6 +47,9 @@ ynh_webpath_available $domain $path_url
# Register (book) web path # Register (book) web path
ynh_webpath_register $app $domain $path_url ynh_webpath_register $app $domain $path_url
# Check memory requirements
check_memory_requirements
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================

View file

@ -41,6 +41,9 @@ ynh_webpath_available $domain $path_url \
test ! -d $final_path \ test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path " || ynh_die "There is already a directory: $final_path "
# Check memory requirements
check_memory_requirements
#================================================= #=================================================
# STANDARD RESTORATION STEPS # STANDARD RESTORATION STEPS
#================================================= #=================================================

View file

@ -35,6 +35,9 @@ admin=$(ynh_app_setting_get $app admin)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get $app db_name)
db_pwd=$(ynh_app_setting_get $app db_pwd) db_pwd=$(ynh_app_setting_get $app db_pwd)
# Check memory requirements
check_memory_requirements_upgrade
#================================================= #=================================================
# BACKUP BEFORE UPGRADE # BACKUP BEFORE UPGRADE
#================================================= #=================================================