mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
More sanity in free memory calculation
Co-authored-by: ljf (zamentur) <zamentur@users.noreply.github.com>
This commit is contained in:
parent
e039d2e195
commit
43992e1338
1 changed files with 4 additions and 7 deletions
|
@ -144,21 +144,18 @@ ynh_add_swap () {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local swap_max_size_kb=$(( size * 1024 ))
|
|
||||||
|
|
||||||
local free_space_kb
|
local free_space_kb
|
||||||
free_space_kb=$(df --block-size=K --output=avail "$swapfile_dir" | sed 1d | sed -e 's/K$//')
|
free_space_kb=$(df --block-size=K --output=avail "$swapfile_dir" | sed 1d | sed -e 's/K$//')
|
||||||
# Because we don't want to fill the disk with a swap file, divide by 2 the available space.
|
# We don't want to fill the disk with a swap file.
|
||||||
local usable_space_kb=$(( free_space_kb / 2 ))
|
local usable_space=$(( free_space_kb / 1024 - 1024 ))
|
||||||
|
|
||||||
# Compare the available space with the size of the swap.
|
# Compare the available space with the size of the swap.
|
||||||
# And set a acceptable size from the request
|
if (( size > usable_space )); then
|
||||||
size_space_ratio=$(( swap_max_size_kb / usable_space_kb + 1 ))
|
|
||||||
if (( size_space_ratio > 4)); then
|
|
||||||
ynh_print_warn --message="Not enough space for a swap file at $swapfile_path."
|
ynh_print_warn --message="Not enough space for a swap file at $swapfile_path."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
swap_size_kb=$(( swap_max_size_kb / size_space_ratio ))
|
swap_size_kb=$(( size * 1024 ))
|
||||||
|
|
||||||
# Configure swappiness
|
# Configure swappiness
|
||||||
if [ ! -f /etc/sysctl.d/999-yunohost-swap.conf ]; then
|
if [ ! -f /etc/sysctl.d/999-yunohost-swap.conf ]; then
|
||||||
|
|
Loading…
Add table
Reference in a new issue