This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ "$(whoami)" != "root" ]; then | |
SUDO=sudo | |
fi | |
if $(type apt-get > /dev/null 2>&1); then | |
${SUDO} fallocate -l 2G /swapfile | |
else | |
${SUDO} dd if=/dev/zero of=/swapfile count=8 bs=256MiB | |
fi | |
${SUDO} chmod 0600 /swapfile | |
${SUDO} mkswap /swapfile | |
${SUDO} swapon /swapfile | |
${SUDO} cp /etc/fstab /etc/fstab.bak | |
echo "/swapfile none swap sw 0 0" | ${SUDO} tee -a /etc/fstab | |
echo 10 | ${SUDO} tee /proc/sys/vm/swappiness | |
echo vm.swappiness = 10 | ${SUDO} tee -a /etc/sysctl.conf | |
echo fs.inotify.max_user_watches=524288 | ${SUDO} tee -a /etc/sysctl.conf | |
${SUDO} chown root:root /swapfile | |
${SUDO} sysctl -p | |
exit 0 |