aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryalh76 <yalh@yahoo.com>2020-05-26 13:18:02 +0200
committeryalh76 <yalh@yahoo.com>2020-05-26 13:18:02 +0200
commit3d713af143776d074d2f37cb0689d777aa632fdf (patch)
tree599ebd2041dbaa97ccc356b9f189b1fd7518ee27
parent80b83a846130e81af1ba20ee5b006d80367edf31 (diff)
downloadmastodon_ynh-3d713af143776d074d2f37cb0689d777aa632fdf.tar.gz
mastodon_ynh-3d713af143776d074d2f37cb0689d777aa632fdf.tar.bz2
mastodon_ynh-3d713af143776d074d2f37cb0689d777aa632fdf.zip
Moving from ynh_check_ram to ynh_get_ram
-rw-r--r--manifest.json2
-rw-r--r--scripts/install6
-rw-r--r--scripts/restore4
-rw-r--r--scripts/upgrade4
-rw-r--r--scripts/ynh_check_ram72
5 files changed, 5 insertions, 83 deletions
diff --git a/manifest.json b/manifest.json
index b54d843..9041ab7 100644
--- a/manifest.json
+++ b/manifest.json
@@ -23,7 +23,7 @@
}
],
"requirements": {
- "yunohost": ">= 3.8"
+ "yunohost": ">= 3.8.1"
},
"multi_instance": true,
"services": [
diff --git a/scripts/install b/scripts/install
index 388b2a3..97dee20 100644
--- a/scripts/install
+++ b/scripts/install
@@ -9,7 +9,6 @@
source _common.sh
source ynh_install_ruby__2
source ynh_add_swap
-source ynh_check_ram
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
-total_memory=$(ynh_check_ram)
-total_swap=$(ynh_check_ram --only_swap)
+total_memory=$(ynh_get_ram --total)
swap_needed=0
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))
fi
diff --git a/scripts/restore b/scripts/restore
index dbcd5cb..ed0b27d 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -10,7 +10,6 @@
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_install_ruby__2
source ../settings/scripts/ynh_add_swap
-source ../settings/scripts/ynh_check_ram
source /usr/share/yunohost/helpers
#=================================================
@@ -87,8 +86,7 @@ chown -R $app: $final_path
#=================================================
ynh_script_progression --message="Adding swap if needed..." --weight=4
-total_memory=$(ynh_check_ram)
-total_swap=$(ynh_check_ram --only_swap)
+total_memory=$(ynh_get_ram --total)
swap_needed=0
if [ $total_memory -lt 2560 ]; then
diff --git a/scripts/upgrade b/scripts/upgrade
index c5be012..9e02c01 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -9,7 +9,6 @@
source _common.sh
source ynh_install_ruby__2
source ynh_add_swap
-source ynh_check_ram
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
-total_memory=$(ynh_check_ram)
-total_swap=$(ynh_check_ram --only_swap)
+total_memory=$(ynh_get_ram --total)
swap_needed=0
if [ $total_memory -lt 2560 ]; then
diff --git a/scripts/ynh_check_ram b/scripts/ynh_check_ram
deleted file mode 100644
index 11012a3..0000000
--- a/scripts/ynh_check_ram
+++ /dev/null
@@ -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
-}