mirror of
https://github.com/darksaid98/ubuntu-server-setup.git
synced 2026-12-01 14:38:58 +00:00
Added swap settings
This commit is contained in:
1 parent
02e48fe201
commit
a82bf4ff21
3 files changed
+38
No files matched your search
@@ -12,6 +12,13 @@ function includeDependencies() {
|
||||
source "${current_dir}/setupLibrary.sh"
|
||||
}
|
||||
|
||||
function setupSwap() {
|
||||
createSwap
|
||||
mountSwap
|
||||
tweakSwapSettings "10" "50"
|
||||
saveSwapSettings
|
||||
}
|
||||
|
||||
current_dir=$(getCurrentDir)
|
||||
includeDependencies
|
||||
|
||||
@@ -32,5 +39,6 @@ read -rp $'Paste in the public SSH key for the new user:\n' sshKey
|
||||
addSSHKey "${username}" "${sshKey}"
|
||||
changeSSHConfig
|
||||
setupUfw
|
||||
setupSwap
|
||||
|
||||
sudo service ssh restart
|
||||
@@ -55,6 +55,24 @@ function createSwap() {
|
||||
sudo swapon /swapfile
|
||||
}
|
||||
|
||||
function mountSwap() {
|
||||
sudo cp /etc/fstab /etc/fstab.bak
|
||||
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
|
||||
}
|
||||
|
||||
function tweakSwapSettings() {
|
||||
local swappiness=${1}
|
||||
local vfs_cache_pressure=${2}
|
||||
|
||||
sudo sysctl vm.swappiness=${swappiness}
|
||||
sudo sysctl vm.vfs_cache_pressure=${vfs_cache_pressure}
|
||||
}
|
||||
|
||||
function saveSwapSettings() {
|
||||
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
|
||||
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
|
||||
}
|
||||
|
||||
function getPhysicalMemory() {
|
||||
local phymem=$(free -g|awk '/^Mem:/{print $2}')
|
||||
if [[ ${phymem} == '0' ]]; then
|
||||
|
||||
@@ -63,6 +63,18 @@ function testSwap() {
|
||||
assertContains "/swapfile" "$(sudo swapon --show)"
|
||||
}
|
||||
|
||||
function testSwapSettings() {
|
||||
local swappiness=$(cat /proc/sys/vm/swappiness)
|
||||
local cache_pressure=$(cat /proc/sys/vm/vfs_cache_pressure)
|
||||
|
||||
tweakSwapSettings 10 50
|
||||
|
||||
assertEquals "$(cat /proc/sys/vm/swappiness)" "10"
|
||||
assertEquals "$(cat /proc/sys/vm/vfs_cache_pressure)" "50"
|
||||
|
||||
tweakSwapSettings "${swappiness}" "${cache_pressure}"
|
||||
}
|
||||
|
||||
function testTeardown () {
|
||||
echo "Test Teardown"
|
||||
|
||||
|
||||
Reference in new issue
Block a user