File tree 3 files changed +38
-0
lines changed
3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,13 @@ function includeDependencies() {
12
12
source " ${current_dir} /setupLibrary.sh"
13
13
}
14
14
15
+ function setupSwap() {
16
+ createSwap
17
+ mountSwap
18
+ tweakSwapSettings " 10" " 50"
19
+ saveSwapSettings
20
+ }
21
+
15
22
current_dir=$( getCurrentDir)
16
23
includeDependencies
17
24
@@ -32,5 +39,6 @@ read -rp $'Paste in the public SSH key for the new user:\n' sshKey
32
39
addSSHKey " ${username} " " ${sshKey} "
33
40
changeSSHConfig
34
41
setupUfw
42
+ setupSwap
35
43
36
44
sudo service ssh restart
Original file line number Diff line number Diff line change @@ -55,6 +55,24 @@ function createSwap() {
55
55
sudo swapon /swapfile
56
56
}
57
57
58
+ function mountSwap() {
59
+ sudo cp /etc/fstab /etc/fstab.bak
60
+ echo ' /swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
61
+ }
62
+
63
+ function tweakSwapSettings() {
64
+ local swappiness=${1}
65
+ local vfs_cache_pressure=${2}
66
+
67
+ sudo sysctl vm.swappiness=${swappiness}
68
+ sudo sysctl vm.vfs_cache_pressure=${vfs_cache_pressure}
69
+ }
70
+
71
+ function saveSwapSettings() {
72
+ echo ' vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
73
+ echo ' vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
74
+ }
75
+
58
76
function getPhysicalMemory() {
59
77
local phymem=$( free -g| awk ' /^Mem:/{print $2}' )
60
78
if [[ ${phymem} == ' 0' ]]; then
Original file line number Diff line number Diff line change @@ -63,6 +63,18 @@ function testSwap() {
63
63
assertContains " /swapfile" " $( sudo swapon --show) "
64
64
}
65
65
66
+ function testSwapSettings() {
67
+ local swappiness=$( cat /proc/sys/vm/swappiness)
68
+ local cache_pressure=$( cat /proc/sys/vm/vfs_cache_pressure)
69
+
70
+ tweakSwapSettings 10 50
71
+
72
+ assertEquals " $( cat /proc/sys/vm/swappiness) " " 10"
73
+ assertEquals " $( cat /proc/sys/vm/vfs_cache_pressure) " " 50"
74
+
75
+ tweakSwapSettings " ${swappiness} " " ${cache_pressure} "
76
+ }
77
+
66
78
function testTeardown () {
67
79
echo " Test Teardown"
68
80
You can’t perform that action at this time.
0 commit comments