-
Notifications
You must be signed in to change notification settings - Fork 1
/
filehandling.sh
executable file
·94 lines (58 loc) · 2.34 KB
/
filehandling.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
echo -e "${_GREEN}FILE HANDLING STARTED${_RESET}"
# Deal with swappiness first
if [ -e /$_SWAPFILE_NAME ]; then
echo "The file /$_SWAPFILE_NAME exists. All Good!!"
else
echo "The file /$_SWAPFILE_NAME does not exist. Fixing That!!!"
sudo fallocate -l $_SWAPFILE_SIZE /$_SWAPFILE_NAME
sudo chmod 600 /$_SWAPFILE_NAME
sudo mkswap /$_SWAPFILE_NAME
sudo swapon /$_SWAPFILE_NAME
sudo echo "/$_SWAPFILE_NAME none swap sw 0 0" | sudo tee -a /etc/fstab
fi
# ensure swappiness and pressure is reduced
if [ "$_SWAPPINESS" -lt "$_SWAPPINESS_TARGET" ]; then
echo "vm.swappiness: $_SWAPPINESS incorrect. Fixing That!!!"
sudo sysctl -w vm.swappiness=$_SWAPPINESS_TARGET
echo "vm.swappiness=$_SWAPPINESS_TARGET" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
else
echo "vm.swappiness: $_SWAPPINESS All Good!!!"
fi
if [ "$_VFS_CACHE_PRESSURE" -lt "$_VFS_CACHE_PRESSURE_TARGET" ]; then
echo "vm.vfs_cache_pressure: $_VFS_CACHE_PRESSURE incorrect. Fixing That!!!"
sudo sysctl -w vm.vfs_cache_pressure=$_VFS_CACHE_PRESSURE_TARGET
echo "vm.vfs_cache_pressure=$VFS__CACHE_PRESSURE_TARGET" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
else
echo "vm.vfs_cache_pressure: $_VFS_CACHE_PRESSURE All Good!!!"
fi
# Deal with open file max limits
if [ "$_FILE_MAX" -lt "$_FILE_MAX_TARGET" ]; then
echo "fs.file-max: $_FILE_MAX incorrect. Fixing That!!!"
sudo sysctl -w fs.file-max=$_FILE_MAX_TARGET
echo "fs.file-max=$_FILE_MAX_TARGET" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
else
echo "fs.file-max: $_FILE_MAX All Good!!!"
fi
if [ "$_ULIMIT" -lt "$_ULIMIT_TARGET" ]; then
echo "ulimit: $_ULIMIT incorrect. Temporarily Fixing That!!!"
ulimit -n $_ULIMIT_TARGET
fi
if [ "$_ULIMIT_HARD" -lt "$_ULIMIT_HARD_TARGET" ]; then
echo "ulimit -Hn: $_ULIMIT_HARD incorrect. Fixing That!!!"
ulimit -Hn $_ULIMIT_HARD_TARGET
echo "$USER hard nofile $_ULIMIT_HARD_TARGET" | sudo tee -a /etc/security/limits.conf
else
echo "ulimit -Hn: $_ULIMIT_HARD All Good!!!"
fi
if [ "$_ULIMIT_SOFT" -lt "$_ULIMIT_SOFT_TARGET" ]; then
echo "ulimit -Sn: $_ULIMIT_SOFT incorrect. Fixing That!!!"
ulimit -Sn $_ULIMIT_SOFT_TARGET
echo "$USER soft nofile $_ULIMIT_SOFT_TARGET" | sudo tee -a /etc/security/limits.conf
else
echo "ulimit -Sn: $_ULIMIT_SOFT All Good!!!"
fi
echo -e "${_CYAN}FILE HANDLING DONE${_RESET}"