Quantcast
Channel: LinuxReaders » Virtualization
Viewing all articles
Browse latest Browse all 10

XenServer – Apply patches using bash script

$
0
0

With the release of XenServer 6.2, Citrix has provided best & easy to use virtulization option for free. Only limitation with free xenserver is you can’t use xencenter to apply patches. Which anyways many Linux Admins must not be using. To patch free xenserver only option is to use cli, you can patch xenserver using cli or by using below mentioned script.

PL TEST THIS SCRIPT THOROUGHLY BEFORE USING FOR PRODUCTION.
Limitations,
This script can not be used to patch diff ver of xenservers at once.

#!/bin/bash
#dpthakar@gmail.com
#http://www.linuxreaders.com
 
#with the citrix xenserver 6.2 release, free xencenter can not be used to patch servers. this script can be used on any of server to patch itself & rest of the xenservers, this script is only tested with stanalone servers, no pool etc.
#pl make sure updates stored under PATCHDIR is for SERVERS mentioned here, e.g patches stored for 6.2 only. Also do not mix diff ver of patches & servers.
NFSSHARE=192.168.1.24:/storage/xen_back
MOUNTDIR=/mnt/back
PATCHDIR=/mnt/back/up
#mention list of the xenserver ip
SERVERS="192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.4"
SUSER=root
SPASS=redhat
 
#check for backup / mount dir.
if [ -d $MOUNTDIR ]
        then
                echo "Mount Dir Exists"
        else
                echo "Mount Dir does not exists, Creating"
                mkdir -p $MOUNTDIR
fi
 
#mount nfs share if not already mounted.
MOUNT=`mount|grep $NFSSHARE -c`
if [ $MOUNT = "1" ]
        then
                echo "NFS already mouted"
        else
                echo "Mounting NFS share"
                mount -t nfs $NFSSHARE $MOUNTDIR
fi
 
 
#list patches for patchdir
PLIST=`ls $PATCHDIR/*.xsupdate | wc -l`
PCOUNT=0
PLINE=1	
ls $PATCHDIR/*.xsupdate > /tmp/patch_list
until [ "$PCOUNT" = "$PLIST" ]	
	do
	PATCH=`gawk FNR==$PLINE /tmp/patch_list`
 
	#upload patch file to all mentioned servers
	echo $SERVERS | sed 's/,/\n/g' > /tmp/patch_server_list
	SLIST=`cat /tmp/patch_server_list | wc -l`
	COUNT=0
	LINE=1
	until [ "$COUNT" = "$SLIST" ]
        	do
			SERVER=`gawk FNR==$LINE /tmp/patch_server_list`
			#upload patch to server
			PATCHUUID=`xe -s $SERVER -u $SUSER -pw $SPASS patch-upload file-name=$PATCH`
			#find server uuid
			HOSTUUID=`xe -s $SERVER -u $SUSER -pw $SPASS host-list params=uuid | gawk -F: '{ print $2 }' | sed 's/ //g' | sed '/^$/d'`
			#apply patch
			echo "Patching $PATCH to Server $SERVER"
			xe -s $SERVER -u $SUSER -pw $SPASS patch-apply uuid=$PATCHUUID host-uuid=$HOSTUUID
			#clean applied patch file from local storage to save space
			xe -s $SERVER -u $SUSER -pw $SPASS patch-clean uuid=$PATCHUUID 
			COUNT=`expr $COUNT + 1`
			LINE=`expr $LINE + 1`
	        done
	PCOUNT=`expr $PCOUNT + 1`
	PLINE=`expr $PLINE + 1`
	done

(Visited 1,267 times, 1 visits today)

Viewing all articles
Browse latest Browse all 10

Trending Articles