1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/glitchsoc_ynh.git synced 2024-09-03 19:15:59 +02:00

Moving from ynh_check_ram to ynh_get_ram

This commit is contained in:
yalh76 2020-05-26 13:18:02 +02:00
parent 80b83a8461
commit 3d713af143
5 changed files with 5 additions and 83 deletions

View file

@ -23,7 +23,7 @@
} }
], ],
"requirements": { "requirements": {
"yunohost": ">= 3.8" "yunohost": ">= 3.8.1"
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [

View file

@ -9,7 +9,6 @@
source _common.sh source _common.sh
source ynh_install_ruby__2 source ynh_install_ruby__2
source ynh_add_swap source ynh_add_swap
source ynh_check_ram
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -134,12 +133,11 @@ ynh_system_user_create --username=$app --home_dir=$final_path
#================================================= #=================================================
ynh_script_progression --message="Adding swap is needed..." --weight=4 ynh_script_progression --message="Adding swap is needed..." --weight=4
total_memory=$(ynh_check_ram) total_memory=$(ynh_get_ram --total)
total_swap=$(ynh_check_ram --only_swap)
swap_needed=0 swap_needed=0
if [ $total_memory -lt 2560 ]; then if [ $total_memory -lt 2560 ]; then
# Need a minimum of 8Go of memory # Need a minimum of 2.5Go of memory
swap_needed=$((2560 - $total_memory)) swap_needed=$((2560 - $total_memory))
fi fi

View file

@ -10,7 +10,6 @@
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_install_ruby__2 source ../settings/scripts/ynh_install_ruby__2
source ../settings/scripts/ynh_add_swap source ../settings/scripts/ynh_add_swap
source ../settings/scripts/ynh_check_ram
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -87,8 +86,7 @@ chown -R $app: $final_path
#================================================= #=================================================
ynh_script_progression --message="Adding swap if needed..." --weight=4 ynh_script_progression --message="Adding swap if needed..." --weight=4
total_memory=$(ynh_check_ram) total_memory=$(ynh_get_ram --total)
total_swap=$(ynh_check_ram --only_swap)
swap_needed=0 swap_needed=0
if [ $total_memory -lt 2560 ]; then if [ $total_memory -lt 2560 ]; then

View file

@ -9,7 +9,6 @@
source _common.sh source _common.sh
source ynh_install_ruby__2 source ynh_install_ruby__2
source ynh_add_swap source ynh_add_swap
source ynh_check_ram
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -231,8 +230,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path
#================================================= #=================================================
ynh_script_progression --message="Adding swap if needed..." --weight=7 ynh_script_progression --message="Adding swap if needed..." --weight=7
total_memory=$(ynh_check_ram) total_memory=$(ynh_get_ram --total)
total_swap=$(ynh_check_ram --only_swap)
swap_needed=0 swap_needed=0
if [ $total_memory -lt 2560 ]; then if [ $total_memory -lt 2560 ]; then

View file

@ -1,72 +0,0 @@
#!/bin/bash
# Check the amount of available RAM
#
# usage: ynh_check_ram [--required=RAM required in Mb] [--no_swap|--only_swap] [--free_ram]
# | arg: -r, --required= - Amount of RAM required in Mb. The helper will return 0 is there's enough RAM, or 1 otherwise.
# If --required isn't set, the helper will print the amount of RAM, in Mb.
# | arg: -s, --no_swap - Ignore swap
# | arg: -o, --only_swap - Ignore real RAM, consider only swap.
# | arg: -f, --free_ram - Count only free RAM, not the total amount of RAM available.
ynh_check_ram () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [r]=required= [s]=no_swap [o]=only_swap [f]=free_ram )
local required
local no_swap
local only_swap
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
required=${required:-}
no_swap=${no_swap:-0}
only_swap=${only_swap:-0}
local total_ram=$(vmstat --stats --unit M | grep "total memory" | awk '{print $1}')
local total_swap=$(vmstat --stats --unit M | grep "total swap" | awk '{print $1}')
local total_ram_swap=$(( total_ram + total_swap ))
local free_ram=$(vmstat --stats --unit M | grep "free memory" | awk '{print $1}')
local free_swap=$(vmstat --stats --unit M | grep "free swap" | awk '{print $1}')
local free_ram_swap=$(( free_ram + free_swap ))
# Use the total amount of ram
local ram=$total_ram_swap
if [ $free_ram -eq 1 ]
then
# Use the total amount of free ram
ram=$free_ram_swap
if [ $no_swap -eq 1 ]
then
# Use only the amount of free ram
ram=$free_ram
elif [ $only_swap -eq 1 ]
then
# Use only the amount of free swap
ram=$free_swap
fi
else
if [ $no_swap -eq 1 ]
then
# Use only the amount of free ram
ram=$total_ram
elif [ $only_swap -eq 1 ]
then
# Use only the amount of free swap
ram=$total_swap
fi
fi
if [ -n "$required" ]
then
# Return 1 if the amount of ram isn't enough.
if [ $ram -lt $required ]
then
return 1
else
return 0
fi
# If no RAM is required, return the amount of available ram.
else
echo $ram
fi
}