-
Notifications
You must be signed in to change notification settings - Fork 7
/
docker-entrypoint.sh
186 lines (163 loc) · 5.22 KB
/
docker-entrypoint.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
# ----------------------------------------------------------------------------------
# Every 20 seconds this script checks the temperature reported by the ambient temperature sensor,
# and if deemed too high sends the raw IPMI command to adjust the fan speed on the R610 server.
# It also sends healthcheck pings to a healthchecks.io service.
#
#
# Requires:
# ipmitool – apt-get install ipmitool
# slacktee.sh – https://github.com/course-hero/slacktee
# ----------------------------------------------------------------------------------
# Set the state of Emergency (is it too hot or not)
EMERGENCY=false
NOTIFY=true
# IPMI SETTINGS:
# DEFAULT IP: 192.168.0.120
IPMIHOST=${IPMIHOST} # <IP Address of the iDRAC on the Server>
IPMIUSER=${IPMIUSER} # <User for the iDRAC>
IPMIPW=${IPMIPW} # <Password for the iDRAC
# HealthCheck HC_URL
HC_URL=${HC_URL} # <Unique Ping URL component>
# Slacktee Configs
WEBHOOK_URL=${WEBHOOK_URL}
UPLOAD_TOKEN=${UPLOAD_TOKEN}
CHANNEL=${CHANNEL}
TMP_DIR=${TMP_DIR}
USERNAME=${USERNAME}
ICON=${ICON}
ATTACHMENT=${ATTACHMENT}
# Configure Slacktee
sed -i 's#webhook_url=""#webhook_url="'"$WEBHOOK_URL"'"#g' /etc/slacktee.conf
sed -i 's/upload_token=""/upload_token="'"$UPLOAD_TOKEN"'"/g' /etc/slacktee.conf
sed -i 's/channel=""/channel="'"$CHANNEL"'"/g' /etc/slacktee.conf
sed -i 's#tmp_dir=""#tmp_dir="'"$TMP_DIR"'"#g' /etc/slacktee.conf
sed -i 's/username=""/username="'"$USERNAME"'"/g' /etc/slacktee.conf
sed -i 's/icon=""/icon="'"$ICON"'"/g' /etc/slacktee.conf
sed -i 's/attachment=""/attachment="'"$ATTACHMENT"'"/g' /etc/slacktee.conf
# TEMPERATURE
# Change this to the temperature in celcius you are comfortable with.
# If the temperature goes above the set degrees it will send raw IPMI command to enable dynamic fan control
# According to iDRAC Min Warning is 42C and Failure (shutdown) is 47C
StartMidTemp="28"
MidTemp=( "28" "29" "30" "31" )
HighTemp=( "32" "33" "34" "35" )
VeryHighTemp=( "36" "37" "38" "39" "40" )
MAXTEMP="40"
# Last Octal controls values to know
# Query Fan speeds
# ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW sdr type fan
#
# Fan Power Percentages
# 0x00 = 0%
# 0x64 = 100%
#
# R610 RPM values
# 0b = 2280 RPM
# 0e = 2640 RPM
# 0f = 2760 RPM
# 10 = 3000 RPM
# 1a = 4800 RPM
# 20 = 5880 RPM
# 30 = 8880 RPM
# 50 = 14640 RPM
# Default level: 3000 RPM
function FanDefault()
{
echo "Info: Activating manual fan speeds (3000 RPM)"
ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW raw 0x30 0x30 0x01 0x00
ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW raw 0x30 0x30 0x02 0xff 0x10
}
# Mid-Level: 5880 RPM
function FanMid()
{
echo "Info: Activating manual fan speeds (5880 RPM)"
ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW raw 0x30 0x30 0x01 0x00
ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW raw 0x30 0x30 0x02 0xff 0x20
}
# High-level: 8800 RPM
function FanHigh()
{
echo "Info: Activating manual fan speeds (8880 RPM)"
ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW raw 0x30 0x30 0x01 0x00
ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW raw 0x30 0x30 0x02 0xff 0x30
}
# Very-High-level: 14640 RPM
function FanVeryHigh()
{
echo "Info: Activating manual fan speeds (14640 RPM)"
ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW raw 0x30 0x30 0x01 0x00
ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW raw 0x30 0x30 0x02 0xff 0x50
}
# Auto-controled
function FanAuto()
{
echo "Info: Dynamic fan control Active ($CurrentTemp C)" | /usr/bin/slacktee.sh -t "R610 [$(hostname)]"
ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW raw 0x30 0x30 0x01 0x01
}
function gettemp()
{
TEMP=$(ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW sdr type temperature |grep Ambient |grep degrees |grep -Po '\d{2}' | tail -1)
echo "$TEMP"
}
function healthcheck()
{
# healthchecks.io
curl -fsS --retry 3 $HC_URL >/dev/null 2>&1
if $EMERGENCY; then
echo "Temperature is NOT OK ($CurrentTemp C). Emergency Status: $EMERGENCY"
else
echo "Temperature is OK ($CurrentTemp C). Emergency Status: $EMERGENCY"
fi
}
# Helper function for does an array contain a this value
array_contains () {
local array="$1[@]"
local seeking=$2
for element in "${!array}"; do
if [[ $element == $seeking ]]; then
return 1
fi
done
return 0
}
# Start by setting the fans to default low level
echo "Info: Activating manual fan speeds (2280 RPM)"
ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW raw 0x30 0x30 0x01 0x00
ipmitool -I lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW raw 0x30 0x30 0x02 0xff 0x0f
while :
do
CurrentTemp=$(gettemp)
if [[ $CurrentTemp > $MAXTEMP ]]; then
EMERGENCY=true
FanAuto
fi
if [[ $CurrentTemp < $StartMidTemp ]]; then
EMERGENCY=false
NOTIFY=false
FanDefault
fi
array_contains MidTemp $CurrentTemp
result=$(echo $?)
if [ "$result" -eq 1 ] ; then
EMERGENCY=false
NOTIFY=false
FanMid
fi
array_contains HighTemp $CurrentTemp
result=$(echo $?)
if [ "$result" -eq 1 ] ; then
EMERGENCY=false
NOTIFY=false
FanHigh
fi
array_contains VeryHighTemp $CurrentTemp
result=$(echo $?)
if [ "$result" -eq 1 ] ; then
EMERGENCY=false
NOTIFY=false
FanVeryHigh
fi
healthcheck
sleep 20
done