-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreboot-node
executable file
·51 lines (44 loc) · 1 KB
/
reboot-node
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
#!/bin/sh
#
NODE=""
function print_usage () {
echo "$0 -n node"
exit 1
}
while getopts n: optargs
do
case "${optargs}" in
n) NODE=$OPTARG
;;
\?) print_usage
;;
esac
done
if [ -z "$NODE" ]
then
print_usage
exit 1
fi
NODEIP=$(oc get nodes -o wide | grep "^${NODE}" | tr -s ' ' | cut -d ' ' -f 6)
CHECK=$(echo $NODEIP | sed -e 's/^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$/X/')
if [ "$CHECK" != "X" ]
then
echo "Error: Can not find node $NODE"
exit 1
fi
oc adm cordon $NODE
oc adm drain $NODE --delete-local-data --ignore-daemonsets --force
echo "Rebooting node $NODE ..."
ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -l core $NODEIP 'sudo systemctl reboot'
echo "Waiting for $NODE to become ready ..."
sleep 30
while true
do
NODESTATUS=$(oc get nodes | grep "^${NODE}" | tr -s ' ' | cut -d ' ' -f 2)
NODESTATUS=$(echo $NODESTATUS | cut -d ',' -f 1)
if [ "$NODESTATUS" = "Ready" ]
then
oc adm uncordon $NODE
break
fi
done