-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-example.sh
85 lines (67 loc) · 1.84 KB
/
update-example.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
#/bin/sh
set -u
# we don't use -e (fail on error here, because we need to handle explicit exit codes)
# alias yum for CENTOS-7
# command -v dnf > /dev/null || alias dnf="yum"
SUSS_URL=http://localhost:9993
function suss {
local max_attempts=150
local attempt=0
local rc=0
while [[ $attempt -lt $max_attempts ]]; do
echo "SUSS: $1"
curl --fail --silent "$SUSS_URL/$1"
rc=$?
if [[ $rc == 0 ]]; then
break
fi
attempt=$(( attempt + 1 ))
sleep 10
echo "SUSS call failed, retrying..."
done
if [[ $rc != "0" ]]; then
echo "SUSS call failed $max_attempts times, stop script execution"
exit 1
fi
}
# check for updates first
# https://dnf.readthedocs.io/en/latest/command_ref.html#check-update-command
yum check-update
rc=$?
if [[ "$rc" == "0" ]]; then
echo "No package updates available, exiting"
exit 0
fi
if [[ "$rc" != "100" ]]; then
echo "dnf check-update exited with code $rc, exiting"
exit 1
fi
# start logstream, will be killed by trap
trap 'echo "stopping logstream";kill $log_pid' SIGINT SIGTERM EXIT
curl --silent $SUSS_URL/logstream & log_pid=$!
# synchronize with other hosts
suss synchronize
# teardown critical workload
suss teardown
# and finally run update
# https://dnf.readthedocs.io/en/latest/command_ref.html#upgrade-command-label
yum update -y
rc=$?
if [[ "$rc" != "0" ]]; then
echo "dnf update failed, releasing lock"
suss release
exit 1
fi
# check if reboot is requred
# https://dnf-plugins-core.readthedocs.io/en/latest/needs_restarting.html
needs-restarting -r
rc=$?
if [[ "$rc" == "0" ]]; then
echo "No reboot required, releasing lock"
suss release
exit 0
fi
# need reboot, release delayed
suss releasedelayed
# and finally reboot, use -t so that script has exit code 0
shutdown -t 1 -r