[Yum] yum-updateonboot

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

 



I've written an init script for RHEL3 that will run 'yum update' on 
boot.  This is intended for anyone who has a machine down for a few days 
to a few weeks or even longer, so that the machine will be updated as 
its booted, instead of having to wait for 4am to roll around.

By default it just runs 'yum update' and keeps going.  By modifying the 
sysconfig file you can specify groups that the script should call 'yum 
groupinstall' on (in case you added packages to your yum groups).  You 
can also specify packages, that will cause the system to reboot if 
they're updated.  This is intended for kernels, so the system will do 
the update, see the kernel was updated, then immediately reboot into the 
new kernel.

I've attached the file.  yum-updateonboot.init is intended to become 
/etc/rc.d/init.d/yum-updateonboot and yum-updateonboot is intended to 
become /etc/sysconfig/yum-updateonboot.

Any questions/comments/etc would be appreciated.  At this point the 
script has only seen minimal testing.


Thanks,


Sean
-------------- next part --------------
#! /bin/bash
#
# yum-updateonboot Updates rpms on the system at boot
#
# chkconfig: 2345 25 75
# description: Runs 'yum update' at boot.  Also calls 'yum groupinstall' for \
#              specified groups
#

# Source function library.
. /etc/init.d/functions

if [ ! -f /etc/sysconfig/yum-updateonboot ]; then
    exit 0
fi

. /etc/sysconfig/yum-updateonboot


# See how we were called.
case "$1" in
  start)
  
	if [ "x$REBOOT_RPMS" != "x" ] ;then
	    TMP1=`/bin/mktemp /tmp/yum-update.XXXXXX`
	    TMP2=`/bin/mktemp /tmp/yum-update.XXXXXX`
	    rpm -q $REBOOT_RPMS > $TMP1
	fi
	echo -n "Updating RPMS on system: "
	yum -y update &> /dev/null && success || failure
	echo
	OLD_IFS=$IFS
	IFS=";"
	for group in $GROUPLIST ; do
	    IFS=$OLD_IFS
	    echo -n $"Installing RPMS in group $group: "
	    yum -y groupinstall "$group" &> /dev/null && success || failure
	    echo
	done
	IFS=$OLD_IFS
	if [ "x$REBOOT_RPMS" != "x" ] ;then
	    rpm -q $REBOOT_RPMS > $TMP2
	    if ! diff $TMP1 $TMP2 &> /dev/null; then 
		rm -f $TMP1
		rm -f $TMP2
		echo "Critical RPMs were updated.. rebooting now"
		/sbin/reboot
	    fi
	    rm -f $TMP1
	    rm -f $TMP2
	fi
	
        ;;
  stop)
        ;;
  status)
	# XXX: FIXME: Run yum check-update
	;;
  restart|reload)
        cd "$CWD"
	$0 stop
	$0 start
	;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac

exit 0
-------------- next part --------------

# IF any of these rpms are updated, the yum-updateonboot init script will
# reboot immediately after the yum update.  To keep yum-updateonboot from
# rebooting the system, comment this line out.
#REBOOT_RPMS="kernel kernel-smp"

# A list of groups that should be updated at boot.  For each group mentioned
# yum-updateonboot will call 'yum -y groupinstall'  Since group names tend to
# have spaces in them, used a semi-colon to separate the group names
#GROUPLIST="My Group;MyOtherGroup;Some_Group;My Group 4"

[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