forked from teamclairvoyant/hadoop-deployment-bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_swappiness.sh
executable file
·116 lines (109 loc) · 4.25 KB
/
change_swappiness.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright Clairvoyant 2015
PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin
VAL=1
# Function to discover basic OS details.
discover_os() {
if command -v lsb_release >/dev/null; then
# CentOS, Ubuntu, RedHatEnterpriseServer, Debian, SUSE LINUX
# shellcheck disable=SC2034
OS=$(lsb_release -is)
# CentOS= 6.10, 7.2.1511, Ubuntu= 14.04, RHEL= 6.10, 7.5, SLES= 11
# shellcheck disable=SC2034
OSVER=$(lsb_release -rs)
# 7, 14
# shellcheck disable=SC2034
OSREL=$(echo "$OSVER" | awk -F. '{print $1}')
# Ubuntu= trusty, wheezy, CentOS= Final, RHEL= Santiago, Maipo, SLES= n/a
# shellcheck disable=SC2034
OSNAME=$(lsb_release -cs)
else
if [ -f /etc/redhat-release ]; then
if [ -f /etc/centos-release ]; then
# shellcheck disable=SC2034
OS=CentOS
# 7.5.1804.4.el7.centos, 6.10.el6.centos.12.3
# shellcheck disable=SC2034
OSVER=$(rpm -qf /etc/centos-release --qf='%{VERSION}.%{RELEASE}\n' | awk -F. '{print $1"."$2}')
# shellcheck disable=SC2034
OSREL=$(rpm -qf /etc/centos-release --qf='%{VERSION}\n')
else
# shellcheck disable=SC2034
OS=RedHatEnterpriseServer
# 7.5, 6Server
# shellcheck disable=SC2034
OSVER=$(rpm -qf /etc/redhat-release --qf='%{VERSION}\n')
if [ "$OSVER" == "6Server" ]; then
# shellcheck disable=SC2034
OSVER=$(rpm -qf /etc/redhat-release --qf='%{RELEASE}\n' | awk -F. '{print $1"."$2}')
# shellcheck disable=SC2034
OSNAME=Santiago
else
# shellcheck disable=SC2034
OSNAME=Maipo
fi
# shellcheck disable=SC2034
OSREL=$(echo "$OSVER" | awk -F. '{print $1}')
fi
elif [ -f /etc/SuSE-release ]; then
if grep -q "^SUSE Linux Enterprise Server" /etc/SuSE-release; then
# shellcheck disable=SC2034
OS="SUSE LINUX"
fi
# shellcheck disable=SC2034
OSVER=$(rpm -qf /etc/SuSE-release --qf='%{VERSION}\n' | awk -F. '{print $1}')
# shellcheck disable=SC2034
OSREL=$(rpm -qf /etc/SuSE-release --qf='%{VERSION}\n' | awk -F. '{print $1}')
# shellcheck disable=SC2034
OSNAME="n/a"
fi
fi
}
echo "********************************************************************************"
echo "*** $(basename "$0")"
echo "********************************************************************************"
# Check to see if we are on a supported OS.
discover_os
if [ "$OS" != RedHatEnterpriseServer ] && [ "$OS" != CentOS ] && [ "$OS" != Debian ] && [ "$OS" != Ubuntu ]; then
echo "ERROR: Unsupported OS."
exit 3
fi
echo "Changing vm.swappiness running value to ${VAL}."
sysctl -w vm.swappiness=$VAL
echo "Setting vm.swappiness startup value to ${VAL}."
if [ "$OS" == RedHatEnterpriseServer ] || [ "$OS" == CentOS ]; then
if [ "$OSREL" == 6 ]; then
if grep -q vm.swappiness /etc/sysctl.conf; then
sed -i -e "/^vm.swappiness/s|=.*|= $VAL|" /etc/sysctl.conf
else
echo "vm.swappiness = $VAL" >>/etc/sysctl.conf
fi
else
if grep -q vm.swappiness /etc/sysctl.conf; then
sed -i -e '/^vm.swappiness/d' /etc/sysctl.conf
fi
install -m 0644 -o root -g root /dev/null /etc/sysctl.d/cloudera.conf
echo "# Tuning for Hadoop installation. CLAIRVOYANT" >/etc/sysctl.d/cloudera.conf
echo "vm.swappiness = $VAL" >>/etc/sysctl.d/cloudera.conf
fi
elif [ "$OS" == Debian ] || [ "$OS" == Ubuntu ]; then
if grep -q vm.swappiness /etc/sysctl.conf; then
sed -i -e '/^vm.swappiness/d' /etc/sysctl.conf
fi
install -m 0644 -o root -g root /dev/null /etc/sysctl.d/cloudera.conf
echo "# Tuning for Hadoop installation. CLAIRVOYANT" >/etc/sysctl.d/cloudera.conf
echo "vm.swappiness = $VAL" >>/etc/sysctl.d/cloudera.conf
fi