Skip to content

Commit

Permalink
feat: Check the RAM amount available (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored May 3, 2024
1 parent aff091d commit fc02ce8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,20 @@ else
fi
fi

# Check available memory as the very last step

RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
RAM_TOTAL=$(free -b | grep -m 1 Mem: | awk '{print $2}')
AVAIL_GB=$(( (RAM_AVAIL + 1073741823)/1073741824 ))
TOTAL_GB=$(( (RAM_TOTAL + 1073741823)/1073741824 ))

if (( (RAM_WANTED + 500000000) > RAM_AVAIL )); then
error "Your configured RAM_SIZE of $WANTED_GB GB is higher than the $AVAIL_GB GB of memory available, please set a lower value."
exit 15
fi

if (( (RAM_WANTED + 1950000000) > RAM_AVAIL )); then
warn "your configured RAM_SIZE of $WANTED_GB GB is much too close to the $AVAIL_GB GB of memory available, please set a lower value."
fi

return 0
8 changes: 2 additions & 6 deletions src/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,11 @@ echo

# Check memory

if (( RAM_WANTED > RAM_AVAIL )); then
error "Your configured RAM_SIZE of $WANTED_GB GB is higher than the $AVAIL_GB GB of memory available."
if (( (RAM_WANTED + 500000000) > RAM_AVAIL )); then
error "Your configured RAM_SIZE of $WANTED_GB GB is higher than the $AVAIL_GB GB of memory available, please set a lower value."
exit 15
fi

if (( (RAM_WANTED + 1950000000) > RAM_AVAIL )); then
warn "your configured RAM_SIZE of $WANTED_GB GB is much too close to the $AVAIL_GB GB of memory available."
fi

# Helper functions

isAlive() {
Expand Down

0 comments on commit fc02ce8

Please sign in to comment.