Dobrev.EU Blog

Things I want to share

Applying Patches to XenServer

| Comments

Introduction

With the release of XenServer 6.2 automated patch management via XenCenter is not possible any more as long as you don’t have a license. So in order to keep your XenServers up-to-date you need to apply them manually on the CLI.

Download the patch

Download the patch from the official XenServer website. One can still use XenCenter to check for patch availability.

Upload a patch to XenServer DB

apply_xenserver_patch.sh
1
[root@UK2SR102 ~]# xe patch-upload -s hostname -u root -pw "yourpass" file-name=<full path to the patch>

This command will return a UUID of the patch you just added to the list of available patches.

Apply the patch to the pool

Good news is that XenServer is applying the patches to the whole pool so you don’t actually need to repeat these steps over and over again

apply_xenserver_patch.sh
1
[root@UK2SR102 ~]# xe -s hostname -u root -pw "yourpass" patch-pool-apply uuid=<uuid from previous step>

How to automate it using a script?

I use the following BASH script to automate the process. Copy the source to your XenServer and give it a try. N.B. This script runs successfully only on XenServer nodes. You need to point it to the Master node of the pool too.

apply_xenserver_patch.sh (apply_xenserver_patch.sh) download
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
#!/bin/bash
#
# apply_xenserver_patch.sh
# 
# This program is used to apply patches to a XenServer pool 
#
# Copyright (C) 2013-2014 Martin Dobrev <martin[dot]dobrev[at]unixsol[dot]co[dot]uk>
# Company: UNIXSOL LTD
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Chanegelog
# =========================================================
#
# v0.0.2  - Initial GNU GPL version
#
##################################################################

set +x

# Default configuration

# Enter the IP or hostname of the XenServer
#
# Default: localhost
XEN_SERVER='localhost'

# Username to connect with
#
# Default: root
XEN_USER='root'

# Password for the XEN_USER
XEN_PASS=''

# Do not chage below this line if you don't know what you do
# You're warned :)

PROG=$(basename $0 .sh)
VER="0.0.2"

function usage() {
cat <<EOF
Usage: ${PROG} -s <server> -u <username> -p <password> -P <patch to apply>
 
        -h      This screen
        -s      Server node. IP or hostname. 
                Default: '${XEN_SERVER}'
        -u      Username to connect with.
                Default: '${XEN_USER}'
        -p      Password
                Default: '${XEN_PASS}'
        -P      Patch to apply
        -v      Version ${VER}
 
This program automates the installation of updates and patches to a XenServer. This program was tested on
XenServer 5.6/6.1/6.2
 
For additional information and modifications contact Martin Dobrev (martin[dot]dobrev[at]unixsol[dot]co[dot]uk)
EOF
}

while getopts "hs:u:p:P:v" OPTION
do
     case $OPTION in
         h)
             usage
             exit 1
             ;;
         s)
             XEN_SERVER=$OPTARG
             ;;
         p)
             XEN_PASS=$OPTARG
             ;;
         u)
             XEN_USER=$OPTARG
             ;;
         P)  PATCH=$OPTARG
             ;;
         v)
             echo "$PROG version $VER"
             exit
             ;;
         ?)
             usage
             exit
             ;;
     esac
done
 
if [ $# -lt 1 ]; then
        usage;
        exit 1;
fi
 
if [[ -z ${XEN_SERVER} ]] || [[ -z ${XEN_USER} ]] || [[ -z ${XEN_PASS} ]] || [[ -z ${PATCH} ]]; then
        echo "Wrong parameters. Check your default settings and options provided!"
        echo ""
        usage
        exit 2;
fi
 
echo "Uploading patch (${PATCH}) to ${XEN_SERVER}"
PATCHUUID=$(xe patch-upload -s ${XEN_SERVER} -u ${XEN_USER} -pw "${XEN_PASS}" file-name="${PATCH}")

echo "Applying patch to pool now. UUID: ${PATCHUUID}"
xe -s ${XEN_SERVER} -u ${XEN_USER} -pw "${XEN_PASS}" patch-pool-apply uuid=${PATCHUUID}
echo "All done..."

Comments