Skip to content

Commit c30da35

Browse files
Brenn Oosterbaanspark404
authored andcommitted
Commit review 9586
Signed-off-by: Hugo Trippaers <htrippaers@schubergphilis.com>
1 parent 6675d2c commit c30da35

1 file changed

Lines changed: 34 additions & 12 deletions

File tree

scripts/vm/hypervisor/xenserver/xenheartbeat.sh

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# to you under the Apache License, Version 2.0 (the
77
# "License"); you may not use this file except in compliance
88
# with the License. You may obtain a copy of the License at
9-
#
9+
#
1010
# http://www.apache.org/licenses/LICENSE-2.0
11-
#
11+
#
1212
# Unless required by applicable law or agreed to in writing,
1313
# software distributed under the License is distributed on an
1414
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -17,9 +17,9 @@
1717
# under the License.
1818

1919
#set -x
20-
20+
2121
usage() {
22-
printf "Usage: %s [uuid of this host] [interval in seconds]\n" $(basename $0) >&2
22+
printf "Usage: %s [uuid of this host] [timeout in seconds] [interval in seconds]\n" $(basename $0) >&2
2323

2424
}
2525

@@ -33,10 +33,24 @@ if [ -z $2 ]; then
3333
exit 3
3434
fi
3535

36+
if [ ! -z $3 ]; then
37+
interval=$3
38+
else
39+
interval=10
40+
fi
41+
42+
if [ $interval -gt $2 ]; then
43+
usage
44+
exit 3
45+
fi
46+
3647
file=/opt/xensource/bin/heartbeat
37-
while true
38-
do
39-
sleep $2
48+
maxtries=$(($2 / $interval))
49+
tries=1
50+
51+
while [ $tries -le $maxtries ]
52+
do
53+
sleep $interval
4054

4155
if [ ! -f $file ]
4256
then
@@ -51,13 +65,17 @@ do
5165
hb=$dir/hb-$1
5266
date +%s | dd of=$hb count=100 bs=1 2>/dev/null
5367
if [ $? -ne 0 ]; then
54-
/usr/bin/logger -t heartbeat "Problem with $hb"
55-
reboot -f
68+
/usr/bin/logger -t heartbeat "Potential problem with $hb: not reachable since $(($tries * $interval)) seconds"
69+
tries=$(($tries + 1))
70+
else
71+
tries=1
5672
fi
5773
else
74+
/usr/bin/logger -t heartbeat "Heartbeat dir not found for $dir"
5875
sed -i /${dir##/*/}/d $file
5976
fi
6077
done
78+
6179
# for nfs
6280
dirs=$(cat $file | grep sr-mount)
6381
for dir in $dirs
@@ -67,13 +85,17 @@ do
6785
hb=$dir/hb-$1
6886
date +%s | dd of=$hb count=100 bs=1 2>/dev/null
6987
if [ $? -ne 0 ]; then
70-
/usr/bin/logger -t heartbeat "Problem with $hb"
71-
reboot -f
88+
/usr/bin/logger -t heartbeat "Potential problem with $hb: not reachable since $(($tries * $interval)) seconds"
89+
tries=$(($tries + 1))
90+
else
91+
tries=1
7292
fi
7393
else
94+
/usr/bin/logger -t heartbeat "Heartbeat mount not found for $dir"
7495
sed -i /${dir##/*/}/d $file
7596
fi
7697
done
77-
7898
done
7999

100+
/usr/bin/logger -t heartbeat "Problem with $hb: not reachable for $2 seconds, rebooting system!"
101+
reboot -f

0 commit comments

Comments
 (0)