Update file run_onchange_before_configure-swap.tmpl
This commit is contained in:
parent
990c3edc32
commit
a4fb1014e3
1 changed files with 22 additions and 20 deletions
|
@ -4,26 +4,28 @@
|
||||||
{{ includeTemplate "universal/profile" }}
|
{{ includeTemplate "universal/profile" }}
|
||||||
{{ includeTemplate "universal/logg" }}
|
{{ includeTemplate "universal/logg" }}
|
||||||
|
|
||||||
MEMORY_IN_KB="$(grep MemTotal /proc/meminfo | sed 's/.* \(.*\) kB/\1/')"
|
if [ ! -f /swapfile ]; then
|
||||||
MEMORY_IN_GB="$((MEMORY_IN_KB / 1024 / 1024))"
|
MEMORY_IN_KB="$(grep MemTotal /proc/meminfo | sed 's/.* \(.*\) kB/\1/')"
|
||||||
|
MEMORY_IN_GB="$((MEMORY_IN_KB / 1024 / 1024))"
|
||||||
|
|
||||||
if [ "$MEMORY_IN_GB" -gt 64 ]; then
|
if [ "$MEMORY_IN_GB" -gt 64 ]; then
|
||||||
SWAP_SPACE="$((MEMORY_IN_GB / 10))"
|
SWAP_SPACE="$((MEMORY_IN_GB / 10))"
|
||||||
elif [ "$MEMORY_IN_GB" -gt 32 ]; then
|
elif [ "$MEMORY_IN_GB" -gt 32 ]; then
|
||||||
SWAP_SPACE="$((MEMORY_IN_GB / 8))"
|
SWAP_SPACE="$((MEMORY_IN_GB / 8))"
|
||||||
elif [ "$MEMORY_IN_GB" -gt 8 ]; then
|
elif [ "$MEMORY_IN_GB" -gt 8 ]; then
|
||||||
SWAP_SPACE="$((MEMORY_IN_GB / 4))"
|
SWAP_SPACE="$((MEMORY_IN_GB / 4))"
|
||||||
else
|
else
|
||||||
SWAP_SPACE="$MEMORY_IN_GB"
|
SWAP_SPACE="$MEMORY_IN_GB"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
logg info "Creating a $SWAP_SPACE GB /swapfile"
|
logg info "Creating a $SWAP_SPACE GB /swapfile"
|
||||||
sudo fallocate -l "$SWAP_SPACE" /swapfile
|
sudo fallocate -l "$SWAP_SPACE" /swapfile
|
||||||
sudo chmod 600 /swapfile
|
sudo chmod 600 /swapfile
|
||||||
sudo mkswap /swapfile
|
sudo mkswap /swapfile
|
||||||
sudo swapon /swapfile
|
sudo swapon /swapfile
|
||||||
if cat /etc/fstab | grep "/swapfile"; then
|
if cat /etc/fstab | grep "/swapfile"; then
|
||||||
sudo sed -i '/\/swapfile/\/swapfile none swap sw 0 0/' /etc/fstab
|
sudo sed -i '/\/swapfile/\/swapfile none swap sw 0 0/' /etc/fstab
|
||||||
else
|
else
|
||||||
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
|
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue