This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
upgradecontainers.sh
executable file
·107 lines (97 loc) · 2.7 KB
/
upgradecontainers.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
#!/bin/bash
SCRIPTSPATH=`dirname ${BASH_SOURCE[0]}`
source $SCRIPTSPATH/lib.sh
if [ -z "$2" ]
then
echo "optional: can pass sender and recipient email address to send an email when there are update errors"
echo "sample call: $0 [email protected] [email protected]"
echo
fi
errorsSender=$1
errorsRecipient=$2
echo "updating the host " `hostname -f`
rootfs=
getOSOfContainer $rootfs
if [[ "$OS" == "CentOS" ]]
then
yum -y update
elif [[ "$OS" == "Fedora" ]]
then
dnf -y update
elif [[ "$OS" == "Ubuntu" ]]
then
apt-get update && apt-get -y upgrade
elif [[ "$OS" == "Debian" ]]
then
apt-get update && apt-get -y upgrade
else
echo "unknown operating system in container " $container
exit -1
fi
errors=
for d in $container_path/*
do
container=`basename $d`
# if the container does not have autostart enabled, don't upgrade it
# we don't want to upgrade temporary or development containers
if [[ "false" == "`lxc config get $container boot.autostart`" ]]
then
continue
fi
if [[ -z "`lxc list $container | grep RUNNING`" ]]
then
# stopped. do not upgrade, potential problems with mysql updates etc.
continue
fi
echo
echo
echo "======================="
echo "updating " $container
echo "======================="
rootfs=$d/rootfs
# version,OS,OSRelease=getOSOfContainer
getOSOfContainer $rootfs
name=`basename $d`
error=0
if [[ "$OS" == "CentOS" ]]
then
(lxc exec $name -- yum -y update ) || error=1
elif [[ "$OS" == "Fedora" ]]
then
(lxc exec $name -- dnf -y update ) || error=1
elif [[ "$OS" == "Ubuntu" ]]
then
(lxc exec $name -- /bin/bash -c 'LANG=C; apt-get update && apt-get -y upgrade || exit -1') || error=1
elif [[ "$OS" == "Debian" ]]
then
(lxc exec $name -- /bin/bash -c 'LANG=C; apt-get update && apt-get -y upgrade || exit -1') || error=1
else
echo "unknown operating system in container " $container
exit -1
fi
if [ $error -eq 1 ]
then
errors="${errors}Error upgrading container $container\n"
fi
done
if [ ! -z "$errors" ]
then
echo
echo
echo "=============================="
echo "problems upgrading containers:"
echo "=============================="
echo -e $errors
if [ ! -z "$errorsRecipient" ]
then
getOSOfContainer "/"
if [[ "$OS" == "CentOS" ]]
then
echo -e "problems upgrading containers on host `hostname -f`: \n $errors" | mail -s "problems upgrading containers on host `hostname -f`" -a "From: $errorsSender" "$errorsRecipient"
elif [[ "$OS" == "Ubuntu" ]]
then
echo -e "problems upgrading containers on host `hostname -f`: \n $errors" | mail -s "problems upgrading containers on host `hostname -f`" -r $errorsSender "$errorsRecipient"
fi
fi
exit -1
fi