| Server IP : 127.0.0.1 / Your IP : 216.73.217.122 Web Server : Apache System : Linux Stag-Enterprise-Production-20-04 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 06:59:36 UTC 2025 x86_64 User : ubuntu ( 1000) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/ubuntu/ |
Upload File : |
#!/bin/bash
# MUST be run as root
if [ "$(whoami)" != "root" ]; then
echo "This script MUST be run as root. Goodbye!"
exit 1
fi
# older convention putting swapfile on app volume, better for GP2 EBS volumes where IOPS are tied to size
#swap_file="/mnt/Sites/swapfile"
# newer convetion putting swapfile on root volume, better for GP3 where base iops is 3k; leaves IOPS on app vol for application
swap_file="/swapfile"
swap_size='1G'
swappiness=10
fallocate -l "$swap_size" "$swap_file"
chmod 600 "$swap_file"
mkswap "$swap_file"
swapon "$swap_file"
sysctl "vm.swappiness=${swappiness}"
#make sure swap is in '/etc/fstab' to presist through reboots
if grep -iq "$swap_file" /etc/fstab; then
echo "Detected /etc/fstab alread contains '${swap_file}'"
else
echo "Adding '${swap_file}' /etc/fstab"
echo "${swap_file} none swap sw 0 0">>/etc/fstab
fi
#make swappiness persist through reboots by editing '/etc/sysctl.conf' with below
if grep -iq "vm.swappiness=${swappiness}" /etc/sysctl.conf; then
echo "Detected /etc/sysctl.conf alread contains 'vm.swappiness=${swappiness}'"
else
echo "Adding 'vm.swappiness=${swappiness}' /etc/sysctl.conf"
echo "vm.swappiness=${swappiness}">>/etc/sysctl.conf
fi