[Yum] Fermi's crontab

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a multi-part message in MIME format.
--------------020702000901040700030502
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Howdy Ho,
I think I've gotten most of the major bugs worked out of this.  It's been 
running a few days on several machines, and seems to do what we want.  We put 
this cron script in the /etc/cron.daily directory.

I really don't plan on you putting this into the product, I just wanted to 
show you what we are doing.

A few notes
1) Yes, it does need to be cleaned up a bit, as far as commented out lines, 
and more comments for readability.
2) Yes, we know that doing yum install is risky (see workgroups).  We keep 
tight control on those sections on the server.  (not that we don't with the 
rest of the server, but you know what I mean)
3) Yes, we do clean up the users regular yum area at the end.  For fermi, we 
have good bandwith pretty much everywhere. It is much more likely that a user 
won't know about the clean command, fill up his disk with old rpms, and yell 
at us, than he will complain because he has to download another rpm.

Troy

-- 
__________________________________________________
Troy Dawson  dawson@xxxxxxxx  (630)840-6468
Fermilab  ComputingDivision/OSS  CSI Group
__________________________________________________

--------------020702000901040700030502
Content-Type: text/plain;
 name="yum.cron"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="yum.cron"

#!/bin/sh
#
#  Yum cron file
#	Designed to work with Fermilab's workgroups
#	Designed to only send mail when something has been updated or installed
#
#  Written by Troy Dawson <dawson@xxxxxxxx>
#
#Change DEBUG to 0 to turn on debugging
DEBUG=0
MAXWAITTIME=60
MAILLIST="root"
#MAILLIST="root,me@xxxxxxxxxxxx,you@xxxxxxxxxxxxxx"

#*******************************************
# Function to ping a server
#  Return 0 - alive and able to access
#  Return 1 - failed
#*******************************************	
ping_server() {
	TESTSERVER=$1
	/usr/bin/ncftpls -t 5 -r 1 ftp://$TESTSERVER.fnal.gov/ > /dev/null 2>&1
	if [ $? -eq 0 ] ; then
		if [ $DEBUG -eq 0 ] ; then
			echo "   Server $TESTSERVER alive and ftpable"
		fi
		return 0
	fi
	if [ $DEBUG -eq 0 ] ; then
		echo "   Server $TESTSERVER not responding"
	fi
	return 1
}

if [ -f /var/lock/subsys/yum ]; then
	if [ $DEBUG -eq 0 ] ; then
		echo "Yum crontab starting"
	fi
	#****************************
	#VARIABLES
	#****************************
	TEMPFILE="/tmp/yum.temp"
	TEMPCONFIGFILE="/tmp/yum.temp.config"
	TEMPMAILFILE="/tmp/yum.temp.mail"
	WORKGROUP="$(cat /etc/workgroup)"
	RELEASE="$(cat /etc/fermi-release | cut -d' ' -f4 | tr -d .)"
	TODAY="$(date +%D)"
	CHANGE=0
	
	#****************************
	#Figure out which server to use
	#****************************	
	if [ $DEBUG -eq 0 ] ; then
		echo "  Finding a random, alive server"
	fi
	#pick the server randomly
	let SERVERNUM=$RANDOM%2	
	if [ $SERVERNUM -eq 0 ] ; then
		SERVER="linux21"
#		SERVER="linux"
	else
		SERVER="yort"
#		SERVER="linux1"
	fi
	#check to see if we can access that server
	ping_server $SERVER
	#if we can't access the server, change servers
	if [ $? -eq 1 ] ; then
		if [ $SERVERNUM -eq 0 ] ; then
			SERVER="yort"
#			SERVER="linux1"
		else
			SERVER="linux21"
#			SERVER="linux"
		fi
		#check to see how these servers work
		ping_server $SERVER
		#we couldn't access any servers, so fail this
		if [ $? -eq 1 ] ; then
			echo "Could not access any distribution servers"
			exit 2
		fi
	fi
	if [ $DEBUG -eq 0 ] ; then
		echo "    Using $SERVER as ftp server"
	fi
	
	#****************************
	#Setup
	#****************************
	rm -f $TEMPMAILFILE
	rm -f $TEMPCONFIGFILE
	rm -f $TEMPFILE

	#****************************
	#Updates Update
	#****************************
	if [ $DEBUG -eq 0 ] ; then
		echo "  Starting Yum for Updates"
		echo "   Creating Config File"
	fi
	rm -f $TEMPCONFIGFILE
	echo "[main]" > $TEMPCONFIGFILE
	echo "" >> $TEMPCONFIGFILE
	echo "[updates]" >> $TEMPCONFIGFILE
	echo "name=$RELEASE updates" >> $TEMPCONFIGFILE
	echo "baseurl=ftp://$SERVER.fnal.gov/linux/$RELEASE/i386/updates/RedHat/RPMS/"; >> $TEMPCONFIGFILE
	if [ $DEBUG -eq 0 ] ; then
		echo "vvvvvvvvvvvvvvvvv"
		cat $TEMPCONFIGFILE
		echo "^^^^^^^^^^^^^^^^^"
		echo "    Starting Yum with command"
		echo "     /usr/sbin/yum -c $TEMPCONFIGFILE -e 0 -d 1 -y update"		
	fi
	/usr/sbin/yum -c $TEMPCONFIGFILE -e 0 -d 1 -y update > $TEMPFILE 2>&1
	if [ -s $TEMPFILE ] ; then
		if [ $DEBUG -eq 0 ] ; then
			echo "    We had changes"
			echo "vvvvvvvvvvvvvvvvv"
			cat $TEMPFILE
			echo "^^^^^^^^^^^^^^^^^"
		fi
		CHANGE=1
		echo " --------------------" >> $TEMPMAILFILE
		echo " YUM - Errata Updates" >> $TEMPMAILFILE
		echo " --------------------" >> $TEMPMAILFILE
		cat $TEMPFILE >> $TEMPMAILFILE
	fi
	#****************************
	#Cleanup Updates
	#****************************
	if [ $DEBUG -eq 0 ] ; then
		echo " Cleaning Up Updates"
	fi
	yum -e 0 -d 0 -c $TEMPCONFIGFILE clean all
	
	#****************************
	#Workgroup Update
	#****************************
	if [ $DEBUG -eq 0 ] ; then
		echo "  Starting Yum for Workgroup"
		echo "   Creating Config File"
	fi
	rm -f $TEMPCONFIGFILE
	echo "[main]" > $TEMPCONFIGFILE
	echo "" >> $TEMPCONFIGFILE
	echo "[workgroup]" >> $TEMPCONFIGFILE
	echo "name=$RELEASE $WORKGROUP workgroup" >> $TEMPCONFIGFILE
	echo "baseurl=ftp://$SERVER.fnal.gov/linux/$RELEASE/i386/Fermi/workgroups/$WORKGROUP/RPMS/"; >> $TEMPCONFIGFILE
	if [ $DEBUG -eq 0 ] ; then
		echo "vvvvvvvvvvvvvvvvv"
		cat $TEMPCONFIGFILE
		echo "^^^^^^^^^^^^^^^^^"
		echo "    Starting Yum with command"
		echo "     /usr/sbin/yum -c $TEMPCONFIGFILE -e 0 -d 1 -y install \'*\'"		
	fi
	/usr/sbin/yum -c $TEMPCONFIGFILE -e 0 -d 1 -y install '*' > $TEMPFILE 2>&1
	if [ -s $TEMPFILE ] ; then
		if [ $DEBUG -eq 0 ] ; then
			echo "    We had changes"
			echo "vvvvvvvvvvvvvvvvv"
			cat $TEMPFILE
			echo "^^^^^^^^^^^^^^^^^"
		fi
		CHANGE=1
		echo " -----------------------" >> $TEMPMAILFILE
		echo " YUM - Workgroup Updates" >> $TEMPMAILFILE
		echo " -----------------------" >> $TEMPMAILFILE
		cat $TEMPFILE >> $TEMPMAILFILE
	fi
	#****************************
	#Cleanup Workgroups
	#****************************
	if [ $DEBUG -eq 0 ] ; then
		echo " Cleaning Up Workgoups"
	fi
	yum -e 0 -d 0 -c $TEMPCONFIGFILE clean all
	
	#****************************
	#Send Mail If Needed
	#****************************
	if [ $CHANGE -eq 1 ] ; then
		if [ $DEBUG -eq 0 ] ; then
			echo " Mail Needs To Be Sent"
			echo "  /bin/mail -s \"YUM: $TODAY\" $MAILLIST "
		fi
		/bin/mail -s "YUM: $TODAY" $MAILLIST < $TEMPMAILFILE
	fi

	#****************************
	#Cleanup
	#****************************
	if [ $DEBUG -eq 0 ] ; then
		echo " Cleaning Up Generic"
	fi
	yum -e 0 -d 0 clean all
	rm -f $TEMPMAILFILE
	rm -f $TEMPCONFIGFILE
	rm -f $TEMPFILE
	if [ $DEBUG -eq 0 ] ; then
		echo "Yum Cron Exiting succesfully"
	fi
else
	if [ $DEBUG -eq 0 ] ; then
		echo "Yum cron not turned on.  Exiting"
	fi
	exit 1
fi
exit 0

--------------020702000901040700030502--



[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux