[yum-commits] Branch 'yum-3_2_X' - 3 commits - etc/0yum.cron etc/Makefile etc/yum-cron etc/yum-cron.sysconf etc/yum-daily.yum etc/yum-weekly.yum Makefile yum-cron/cleanup.yum yum-cron/Makefile yum-cron/update.yum yum-cron/yum-cleanup.cron.sh yum-cron/yum-cron.sh yum-cron/yum-cron.sysconfig yum-cron/yum-cron.sysvinit yum-cron/yum-update.cron.sh yum.spec
James Antill
james at osuosl.org
Thu Jul 28 21:19:52 UTC 2011
Makefile | 6 +
etc/0yum.cron | 141 -------------------------------------------
etc/Makefile | 7 --
etc/yum-cron | 102 -------------------------------
etc/yum-cron.sysconf | 58 -----------------
etc/yum-daily.yum | 3
etc/yum-weekly.yum | 4 -
yum-cron/Makefile | 19 +++++
yum-cron/cleanup.yum | 4 +
yum-cron/update.yum | 3
yum-cron/yum-cleanup.cron.sh | 27 ++++++++
yum-cron/yum-cron.sh | 138 ++++++++++++++++++++++++++++++++++++++++++
yum-cron/yum-cron.sysconfig | 64 +++++++++++++++++++
yum-cron/yum-cron.sysvinit | 102 +++++++++++++++++++++++++++++++
yum-cron/yum-update.cron.sh | 25 +++++++
yum.spec | 14 ++--
16 files changed, 396 insertions(+), 321 deletions(-)
New commits:
commit 2592de5f05c060b906ee8089b841d0fe40f3ed5d
Author: Matthew Miller <mattdm at mattdm.org>
Date: Thu Jul 28 16:56:03 2011 -0400
Previously, the entire yum-cron shell script lived in /etc/cron.daily, using options set in /etc/sysconfig/yum-cron to further restrict the days when updates and cleanup are done. This moves the main functionality to a stand-alone shell script, but the logic for days-to-run stays in the cron scripts. That keeps everything compatible and is nice and simple, but also allows one to replace the cron configuration with, for example, updates which run multiple times per day.
The current possible actions for yum-cron are update and cleanup; update has
special-case code to handle check-only or download-only; cleanup just runs
the commands in cleanup.yum. It would be easy to add other such actions.
diff --git a/Makefile b/Makefile
index 820e251..f8212ec 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-SUBDIRS = rpmUtils yum etc docs po
+SUBDIRS = rpmUtils yum yum-cron etc docs po
PYFILES = $(wildcard *.py)
PYLINT_MODULES = *.py yum rpmUtils
PYLINT_IGNORE = oldUtils.py
diff --git a/yum-cron/yum-cleanup.cron.sh b/yum-cron/yum-cleanup.cron.sh
new file mode 100755
index 0000000..0842135
--- /dev/null
+++ b/yum-cron/yum-cleanup.cron.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Only run if this flag file is set (by /etc/rc.d/init.d/yum-cron)
+if [[ ! -f /var/lock/subsys/yum-cron ]]; then
+ exit 0
+fi
+
+# Grab config settings
+if [[ -f /etc/sysconfig/yum-cron ]]; then
+ source /etc/sysconfig/yum-cron
+fi
+
+# Only run on certain days of the week
+dow=`date +%w`
+DAYS_OF_WEEK=${DAYS_OF_WEEK:-0123456}
+if [[ "${DAYS_OF_WEEK/$dow/}" == "${DAYS_OF_WEEK}" ]]; then
+ exit 0
+fi
+
+# And only _clean_ on a subset of that
+CLEANDAY=${CLEANDAY:-0}
+if [[ "${CLEANDAY/$dow/}" == "${CLEANDAY}" ]]; then
+ exit 0
+fi
+
+# Action!
+exec /usr/sbin/yum-cron cleanup
diff --git a/yum-cron/yum-cron.sh b/yum-cron/yum-cron.sh
index 0cfaa4b..d1a32ec 100755
--- a/yum-cron/yum-cron.sh
+++ b/yum-cron/yum-cron.sh
@@ -1,29 +1,29 @@
#!/bin/bash
-# Only run if this flag file is set (by /etc/rc.d/init.d/yum-cron)
-if [ ! -f /var/lock/subsys/yum-cron ]; then
- exit 0
-fi
-
-DAILYSCRIPT=/etc/yum/yum-daily.yum
-WEEKLYSCRIPT=/etc/yum/yum-weekly.yum
LOCKDIR=/var/lock/yum-cron.lock
LOCKFILE=$LOCKDIR/pidfile
TSLOCK=$LOCKDIR/ts.lock
+SCRIPTDIR=/usr/share/yum-cron/
+
+if [ -z "$1" ]; then
+ echo "Usage: yum-cron {update|cleanup|...}"
+ exit 1
+else
+ ACTION=$1
+fi
+
+YUMSCRIPT=${SCRIPTDIR}/${ACTION}.yum
+if [ ! -r $YUMSCRIPT ]; then
+ echo "Script for action \"$ACTION\" is not readable in $SCRIPTDIR."
+ exit 1
+fi
# Grab config settings
if [ -f /etc/sysconfig/yum-cron ]; then
source /etc/sysconfig/yum-cron
fi
# set default for SYSTEMNAME
-[ -z "$SYSTEMNAME" ] && SYSTEMNAME=$(hostname)
-
-# Only run on certain days of the week
-dow=`date +%w`
-DAYS_OF_WEEK=${DAYS_OF_WEEK:-0123456}
-if [ "${DAYS_OF_WEEK/$dow/}" == "${DAYS_OF_WEEK}" ]; then
- exit 0
-fi
+[ -z "$SYSTEMNAME" ] && SYSTEMNAME=$( hostname )
# if DOWNLOAD_ONLY is set then we force CHECK_ONLY too.
# Gotta check before one can download!
@@ -35,11 +35,6 @@ YUMTMP=$(mktemp /var/run/yum-cron.XXXXXX)
touch $YUMTMP
[ -x /sbin/restorecon ] && /sbin/restorecon $YUMTMP
-# Random wait function
-random_wait() {
- sleep $(( $RANDOM % ($RANDOMWAIT * 60) + 1 ))
-}
-
# Note - the lockfile code doesn't try and use YUMTMP to email messages nicely.
# Too many ways to die, this gets handled by normal cron error mailing.
# Try mkdir for the lockfile, will test for and make it in one atomic action
@@ -80,53 +75,55 @@ else
exit 0
else
# lock was invalid, restart
- echo "yum-cron: removing stale lock belonging to stale PID ${OTHERPID}" >&2
+ echo "yum-cron: removing stale lock belonging to stale PID ${OTHERPID}" >&2
echo "yum-cron: restarting myself" >&2
exec $0 "$@"
fi
fi
fi
-# Then check for updates and/or do them, as configured
+# Now, do the actual work; we special case "update" because it has
+# complicated conditionals; for everything else we just run yum with the
+# right parameters and corresponding script. Right now, that's just
+# "cleanup" but theoretically there could be other actions.
+
{
- # First, if this is CLEANDAY, do so
- CLEANDAY=${CLEANDAY:-0}
- if [ ! "${CLEANDAY/$dow/}" == "${CLEANDAY}" ]; then
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $WEEKLYSCRIPT
- fi
+ case "$ACTION" in
+ update)
+ if [ "$CHECK_ONLY" == "yes" ]; then
+ touch $TSLOCK
+ /usr/bin/yum $YUM_PARAMETER -e 0 -d 0 -y check-update 1> /dev/null 2>&1
+ case $? in
+ 1) exit 1;;
+ 100) echo "New updates available for host $SYSTEMNAME";
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y -C check-update
+ if [ "$DOWNLOAD_ONLY" == "yes" ]; then
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y --downloadonly update
+ echo "Updates downloaded. Use \"yum -C update\" manually to install them."
+ fi
+ ;;
+ esac
+ elif [ "$CHECK_FIRST" == "yes" ]; then
+ # Don't run if we can't access the repos
+ touch $TSLOCK
+ /usr/bin/yum $YUM_PARAMETER -e 0 -d 0 check-update 2>&-
+ case $? in
+ 1) exit 1;;
+ 100) /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y update yum
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $YUMSCRIPT
+ ;;
+ esac
+ else
+ touch $TSLOCK
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y update yum
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $YUMSCRIPT
+ fi
+ ;;
+ *)
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $YUMSCRIPT
+ ;;
+ esac
- # Now continue to do the real work
- if [ "$CHECK_ONLY" == "yes" ]; then
- random_wait
- touch $TSLOCK
- /usr/bin/yum $YUM_PARAMETER -e 0 -d 0 -y check-update 1> /dev/null 2>&1
- case $? in
- 1) exit 1;;
- 100) echo "New updates available for host `/bin/hostname`";
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y -C check-update
- if [ "$DOWNLOAD_ONLY" == "yes" ]; then
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y --downloadonly update
- echo "Updates downloaded, use \"yum -C update\" manually to install them."
- fi
- ;;
- esac
- elif [ "$CHECK_FIRST" == "yes" ]; then
- # Don't run if we can't access the repos
- random_wait
- touch $TSLOCK
- /usr/bin/yum $YUM_PARAMETER -e 0 -d 0 check-update 2>&-
- case $? in
- 1) exit 1;;
- 100) /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y update yum
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $DAILYSCRIPT
- ;;
- esac
- else
- random_wait
- touch $TSLOCK
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y update yum
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $DAILYSCRIPT
- fi
} >> $YUMTMP 2>&1
if [ ! -z "$MAILTO" ] && [ -x /bin/mail ]; then
diff --git a/yum-cron/yum-cron.sysconfig b/yum-cron/yum-cron.sysconfig
index 930341c..5b40237 100644
--- a/yum-cron/yum-cron.sysconfig
+++ b/yum-cron/yum-cron.sysconfig
@@ -25,9 +25,11 @@ DOWNLOAD_ONLY=no
# Level 0 is the default
# DEBUG_LEVEL=1
-# randomwait is used by yum to wait random time
-# default is 60 so yum waits random time from 1 to 60 minutes
-# the value must not be zero
+# Wait a random time before applying updates.
+# With a value of 60, yum-cron will waits random time from 1 to 60 minutes.
+# The value must not be zero
+# Note that this parameter affects the daily cron script; if you change that
+# file or run yum-cron in a different way it will have no effect.
RANDOMWAIT="60"
# if MAILTO is set and the mail command is available, the mail command
@@ -44,10 +46,14 @@ MAILTO=
# you may set DAYS_OF_WEEK to the days of the week you want to run
# default is every day
+# Note that this parameter affects the daily cron script; if you change that
+# file or run yum-cron in a different way it will have no effect.
#DAYS_OF_WEEK="0123456"
# which day should it do cleanup on? defaults to 0 (Sunday). If this day isn't in the
# DAYS_OF_WEEK above, it'll never happen
+# Note that this parameter affects the daily cron script; if you change that
+# file or run yum-cron in a different way it will have no effect.
CLEANDAY="0"
# set to yes to make the yum-cron service to wait for transactions to complete
diff --git a/yum-cron/yum-update.cron.sh b/yum-cron/yum-update.cron.sh
new file mode 100755
index 0000000..1801a11
--- /dev/null
+++ b/yum-cron/yum-update.cron.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Only run if this flag file is set (by /etc/rc.d/init.d/yum-cron)
+if [[ ! -f /var/lock/subsys/yum-cron ]]; then
+ exit 0
+fi
+
+# Grab config settings
+if [[ -f /etc/sysconfig/yum-cron ]]; then
+ source /etc/sysconfig/yum-cron
+fi
+
+# Only run on certain days of the week
+dow=`date +%w`
+DAYS_OF_WEEK=${DAYS_OF_WEEK:-0123456}
+if [[ "${DAYS_OF_WEEK/$dow/}" == "${DAYS_OF_WEEK}" ]]; then
+ exit 0
+fi
+
+# Random wait
+[[ $RANDOMWAIT -gt 0 ]] && sleep $(( $RANDOM % ($RANDOMWAIT * 60) + 1 ))
+
+# Action!
+exec /usr/sbin/yum-cron update
+
diff --git a/yum.spec b/yum.spec
index 9e7ed43..825f745 100644
--- a/yum.spec
+++ b/yum.spec
@@ -193,13 +193,14 @@ exit 0
%files cron
%defattr(-,root,root)
%doc COPYING
-%{_sysconfdir}/cron.daily/0yum.cron
-%config(noreplace) %{_sysconfdir}/yum/yum-daily.yum
-%config(noreplace) %{_sysconfdir}/yum/yum-weekly.yum
+%config(noreplace) %{_sysconfdir}/cron.daily/yum-update.cron
+%config(noreplace) %{_sysconfdir}/cron.daily/yum-cleanup.cron
%{_sysconfdir}/rc.d/init.d/yum-cron
+%{_sbindir}/yum-cron
%config(noreplace) %{_sysconfdir}/sysconfig/yum-cron
-
-
+%dir %{_datadir}/yum-cron
+%{_datadir}/yum-cron/update.yum
+%{_datadir}/yum-cron/cleanup.yum
%files updatesd
@@ -212,6 +213,9 @@ exit 0
%{_mandir}/man*/yum-updatesd*
%changelog
+* Thu Jul 28 2011 Matthew Miller <mattdm at mattdm.org>
+- reorganize yum-cron to allow more flexible scheduling
+
* Wed Apr 20 2011 James Antill <james at fedoraproject.org>
- 3.4.1
- umask bug fix.
commit d74e9e6c77346359e95bdce543fc4e347ef0128e
Author: Matthew Miller <mattdm at mattdm.org>
Date: Thu Jul 28 16:49:11 2011 -0400
Move around some yum-cron files (and update the corresponding makefile) in preparation for re-jiggering.
diff --git a/etc/0yum.cron b/etc/0yum.cron
deleted file mode 100755
index 0cfaa4b..0000000
--- a/etc/0yum.cron
+++ /dev/null
@@ -1,141 +0,0 @@
-#!/bin/bash
-
-# Only run if this flag file is set (by /etc/rc.d/init.d/yum-cron)
-if [ ! -f /var/lock/subsys/yum-cron ]; then
- exit 0
-fi
-
-DAILYSCRIPT=/etc/yum/yum-daily.yum
-WEEKLYSCRIPT=/etc/yum/yum-weekly.yum
-LOCKDIR=/var/lock/yum-cron.lock
-LOCKFILE=$LOCKDIR/pidfile
-TSLOCK=$LOCKDIR/ts.lock
-
-# Grab config settings
-if [ -f /etc/sysconfig/yum-cron ]; then
- source /etc/sysconfig/yum-cron
-fi
-# set default for SYSTEMNAME
-[ -z "$SYSTEMNAME" ] && SYSTEMNAME=$(hostname)
-
-# Only run on certain days of the week
-dow=`date +%w`
-DAYS_OF_WEEK=${DAYS_OF_WEEK:-0123456}
-if [ "${DAYS_OF_WEEK/$dow/}" == "${DAYS_OF_WEEK}" ]; then
- exit 0
-fi
-
-# if DOWNLOAD_ONLY is set then we force CHECK_ONLY too.
-# Gotta check before one can download!
-if [ "$DOWNLOAD_ONLY" == "yes" ]; then
- CHECK_ONLY=yes
-fi
-
-YUMTMP=$(mktemp /var/run/yum-cron.XXXXXX)
-touch $YUMTMP
-[ -x /sbin/restorecon ] && /sbin/restorecon $YUMTMP
-
-# Random wait function
-random_wait() {
- sleep $(( $RANDOM % ($RANDOMWAIT * 60) + 1 ))
-}
-
-# Note - the lockfile code doesn't try and use YUMTMP to email messages nicely.
-# Too many ways to die, this gets handled by normal cron error mailing.
-# Try mkdir for the lockfile, will test for and make it in one atomic action
-if mkdir $LOCKDIR 2>/dev/null; then
- # store the current process ID in there so we can check for staleness later
- echo "$$" >"${LOCKFILE}"
- # and clean up locks and tempfile if the script exits or is killed
- trap "{ rm -f $LOCKFILE $TSLOCK; rmdir $LOCKDIR 2>/dev/null; rm -f $YUMTMP; exit 255; }" INT TERM EXIT
-else
- # lock failed, check if process exists. First, if there's no PID file
- # in the lock directory, something bad has happened, we can't know the
- # process name, so clean up the old lockdir and restart
- if [ ! -f $LOCKFILE ]; then
- rmdir $LOCKDIR 2>/dev/null
- echo "yum-cron: no lock PID, clearing and restarting myself" >&2
- exec $0 "$@"
- fi
- OTHERPID="$(cat "${LOCKFILE}")"
- # if cat wasn't able to read the file anymore, another instance probably is
- # about to remove the lock -- exit, we're *still* locked
- if [ $? != 0 ]; then
- echo "yum-cron: lock failed, PID ${OTHERPID} is active" >&2
- exit 0
- fi
- if ! kill -0 $OTHERPID &>/dev/null; then
- # lock is stale, remove it and restart
- echo "yum-cron: removing stale lock of nonexistant PID ${OTHERPID}" >&2
- rm -rf "${LOCKDIR}"
- echo "yum-cron: restarting myself" >&2
- exec $0 "$@"
- else
- # Remove stale (more than a day old) lockfiles
- find $LOCKDIR -type f -name 'pidfile' -amin +1440 -exec rm -rf $LOCKDIR \;
- # if it's still there, it wasn't too old, bail
- if [ -f $LOCKFILE ]; then
- # lock is valid and OTHERPID is active - exit, we're locked!
- echo "yum-cron: lock failed, PID ${OTHERPID} is active" >&2
- exit 0
- else
- # lock was invalid, restart
- echo "yum-cron: removing stale lock belonging to stale PID ${OTHERPID}" >&2
- echo "yum-cron: restarting myself" >&2
- exec $0 "$@"
- fi
- fi
-fi
-
-# Then check for updates and/or do them, as configured
-{
- # First, if this is CLEANDAY, do so
- CLEANDAY=${CLEANDAY:-0}
- if [ ! "${CLEANDAY/$dow/}" == "${CLEANDAY}" ]; then
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $WEEKLYSCRIPT
- fi
-
- # Now continue to do the real work
- if [ "$CHECK_ONLY" == "yes" ]; then
- random_wait
- touch $TSLOCK
- /usr/bin/yum $YUM_PARAMETER -e 0 -d 0 -y check-update 1> /dev/null 2>&1
- case $? in
- 1) exit 1;;
- 100) echo "New updates available for host `/bin/hostname`";
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y -C check-update
- if [ "$DOWNLOAD_ONLY" == "yes" ]; then
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y --downloadonly update
- echo "Updates downloaded, use \"yum -C update\" manually to install them."
- fi
- ;;
- esac
- elif [ "$CHECK_FIRST" == "yes" ]; then
- # Don't run if we can't access the repos
- random_wait
- touch $TSLOCK
- /usr/bin/yum $YUM_PARAMETER -e 0 -d 0 check-update 2>&-
- case $? in
- 1) exit 1;;
- 100) /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y update yum
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $DAILYSCRIPT
- ;;
- esac
- else
- random_wait
- touch $TSLOCK
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y update yum
- /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $DAILYSCRIPT
- fi
-} >> $YUMTMP 2>&1
-
-if [ ! -z "$MAILTO" ] && [ -x /bin/mail ]; then
-# if MAILTO is set, use mail command (ie better than standard mail with cron output)
- [ -s "$YUMTMP" ] && mail -s "System update: $SYSTEMNAME" $MAILTO < $YUMTMP
-else
-# default behavior is to use cron's internal mailing of output from cron-script
- cat $YUMTMP
-fi
-rm -f $YUMTMP
-
-exit 0
diff --git a/etc/Makefile b/etc/Makefile
index 29a7f95..a512cdf 100644
--- a/etc/Makefile
+++ b/etc/Makefile
@@ -29,10 +29,3 @@ install:
mkdir -p $(DESTDIR)/etc/bash_completion.d
install -m 644 yum.bash $(DESTDIR)/etc/bash_completion.d
- mkdir -p $(DESTDIR)/etc/cron.daily
- mkdir -p $(DESTDIR)/etc/sysconfig/
- install -D -m 755 0yum.cron $(DESTDIR)/etc/cron.daily/0yum.cron
- install -D -m 755 yum-cron $(DESTDIR)/etc/rc.d/init.d/yum-cron
- install -D -m 644 yum-daily.yum $(YUMETC)/yum-daily.yum
- install -D -m 644 yum-weekly.yum $(YUMETC)/yum-weekly.yum
- install -D -m 644 yum-cron.sysconf $(DESTDIR)/etc/sysconfig/yum-cron
diff --git a/etc/yum-cron b/etc/yum-cron
deleted file mode 100755
index 63c5ec0..0000000
--- a/etc/yum-cron
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/bin/bash
-#
-# yum-cron This shell script enables the automatic use of YUM
-#
-# Author: Seth Vidal <skvidal at phy.duke.edu>
-#
-# chkconfig: - 50 01
-#
-# description: Enable daily run of yum, a program updater.
-# processname: yum-cron
-# config: /etc/yum/yum-daily.yum
-#
-
-# source function library
-. /etc/rc.d/init.d/functions
-
-test -f /etc/sysconfig/yum-cron && . /etc/sysconfig/yum-cron
-
-lockfile=/var/lock/subsys/yum-cron
-tslock=/var/lock/yum-cron.lock/ts.lock
-yumcronpid=/var/lock/yum-cron.lock/pidfile
-
-RETVAL=0
-
-start() {
- echo -n $"Enabling nightly yum update: "
- touch "$lockfile" && success || failure
- RETVAL=$?
- echo
-}
-
-stop() {
- echo -n $"Disabling nightly yum update: "
- if [ -f "$yumcronpid" -a "$SERVICE_WAITS" = "yes" ]; then
- yum_done=0
- if [ ! -f $tslock ]; then
- # No transaction yet in progress, just kill it
- kill `cat $yumcronpid > /dev/null 2>&1` > /dev/null 2>&1
- yum_done=1
- fi
- if [ $yum_done -eq 0 ]; then
- echo -n $"Waiting for yum "
- if [ -z "$SERVICE_WAIT_TIME" ]; then
- SERVICE_WAIT_TIME=300
- fi
- start=`date +%s`
- end=`expr $start + $SERVICE_WAIT_TIME`
- while [ `date +%s` -le $end ]
- do
- sleep 5
- if [ ! -f "$tslock" ]; then
- yum_done=1
- break
- fi
- done
- if [ $yum_done -eq 1 ]; then
- echo -n " ok "
- else
- echo -n " failed "
- fi
- fi
- fi
- rm -f "$lockfile" && success || failure
- RETVAL=$?
- echo
-}
-
-restart() {
- stop
- start
-}
-
-case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart|force-reload)
- restart
- ;;
- reload)
- ;;
- condrestart)
- [ -f "$lockfile" ] && restart
- ;;
- status)
- if [ -f $lockfile ]; then
- echo $"Nightly yum update is enabled."
- RETVAL=0
- else
- echo $"Nightly yum update is disabled."
- RETVAL=3
- fi
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
- exit 1
-esac
-
-exit $RETVAL
diff --git a/etc/yum-cron.sysconf b/etc/yum-cron.sysconf
deleted file mode 100644
index 930341c..0000000
--- a/etc/yum-cron.sysconf
+++ /dev/null
@@ -1,58 +0,0 @@
-# Pass any given paramter to yum, as run in all the scripts invoked
-# by this package. Be aware that this is global, and yum is invoked in
-# several modes by these scripts for which your own parameter might not
-# be appropriate
-YUM_PARAMETER=
-
-# Don't install, just check (valid: yes|no)
-CHECK_ONLY=no
-
-# Check to see if you can reach the repos before updating (valid: yes|no)
-CHECK_FIRST=no
-
-# Don't install, just check and download (valid: yes|no)
-# Implies CHECK_ONLY=yes (gotta check first to see what to download)
-DOWNLOAD_ONLY=no
-
-# Error level, practical range 0-10, 0 means print only critical errors which
-# you must be told, 1 means print all errors, even ones that are not important
-# Level 0 is the default
-# ERROR_LEVEL=0
-
-# Debug level, practical range 0-10, higher number means more output
-# Level 1 is a useful level if you want to see what's been done and
-# don't want to read /var/log/yum.log
-# Level 0 is the default
-# DEBUG_LEVEL=1
-
-# randomwait is used by yum to wait random time
-# default is 60 so yum waits random time from 1 to 60 minutes
-# the value must not be zero
-RANDOMWAIT="60"
-
-# if MAILTO is set and the mail command is available, the mail command
-# is used to deliver yum output
-
-# by default MAILTO is unset, so crond mails the output by itself
-# example: MAILTO=root
-MAILTO=
-
-# you may set SYSTEMNAME if you want your yum emails tagged differently
-# default is output of hostname command
-# this variable is used only if MAILTO is set too
-#SYSTEMNAME=""
-
-# you may set DAYS_OF_WEEK to the days of the week you want to run
-# default is every day
-#DAYS_OF_WEEK="0123456"
-
-# which day should it do cleanup on? defaults to 0 (Sunday). If this day isn't in the
-# DAYS_OF_WEEK above, it'll never happen
-CLEANDAY="0"
-
-# set to yes to make the yum-cron service to wait for transactions to complete
-SERVICE_WAITS=yes
-
-# set maximum time period (in seconds) for the yum-cron service to wait for
-# transactions to complete. The default is 300 seconds (5 minutes)
-SERVICE_WAIT_TIME=300
diff --git a/etc/yum-daily.yum b/etc/yum-daily.yum
deleted file mode 100644
index 5d4e874..0000000
--- a/etc/yum-daily.yum
+++ /dev/null
@@ -1,3 +0,0 @@
-update
-ts run
-exit
diff --git a/etc/yum-weekly.yum b/etc/yum-weekly.yum
deleted file mode 100644
index c60fa08..0000000
--- a/etc/yum-weekly.yum
+++ /dev/null
@@ -1,4 +0,0 @@
-clean packages
-clean expire-cache
-ts run
-exit
diff --git a/yum-cron/Makefile b/yum-cron/Makefile
new file mode 100644
index 0000000..d68659a
--- /dev/null
+++ b/yum-cron/Makefile
@@ -0,0 +1,19 @@
+all:
+ echo "Nothing to do"
+
+clean:
+ rm -f *~
+
+install:
+ mkdir -p $(DESTDIR)/etc/cron.daily
+ mkdir -p $(DESTDIR)/etc/rc.d/init.d
+ mkdir -p $(DESTDIR)/usr/sbin
+ mkdir -p $(DESTDIR)/etc/sysconfig
+ mkdir -p $(DESTDIR)/usr/share/yum-cron
+ install -D -m 755 yum-update.cron.sh $(DESTDIR)/etc/cron.daily/yum-update.cron
+ install -D -m 755 yum-cleanup.cron.sh $(DESTDIR)/etc/cron.daily/yum-cleanup.cron
+ install -D -m 755 yum-cron.sysvinit $(DESTDIR)/etc/rc.d/init.d/yum-cron
+ install -D -m 755 yum-cron.sh $(DESTDIR)/usr/sbin/yum-cron
+ install -D -m 644 yum-cron.sysconfig $(DESTDIR)/etc/sysconfig/yum-cron
+ install -D -m 644 update.yum $(DESTDIR)/usr/share/yum-cron/update.yum
+ install -D -m 644 cleanup.yum $(DESTDIR)/usr/share/yum-cron/cleanup.yum
diff --git a/yum-cron/cleanup.yum b/yum-cron/cleanup.yum
new file mode 100644
index 0000000..c60fa08
--- /dev/null
+++ b/yum-cron/cleanup.yum
@@ -0,0 +1,4 @@
+clean packages
+clean expire-cache
+ts run
+exit
diff --git a/yum-cron/update.yum b/yum-cron/update.yum
new file mode 100644
index 0000000..5d4e874
--- /dev/null
+++ b/yum-cron/update.yum
@@ -0,0 +1,3 @@
+update
+ts run
+exit
diff --git a/yum-cron/yum-cron.sh b/yum-cron/yum-cron.sh
new file mode 100755
index 0000000..0cfaa4b
--- /dev/null
+++ b/yum-cron/yum-cron.sh
@@ -0,0 +1,141 @@
+#!/bin/bash
+
+# Only run if this flag file is set (by /etc/rc.d/init.d/yum-cron)
+if [ ! -f /var/lock/subsys/yum-cron ]; then
+ exit 0
+fi
+
+DAILYSCRIPT=/etc/yum/yum-daily.yum
+WEEKLYSCRIPT=/etc/yum/yum-weekly.yum
+LOCKDIR=/var/lock/yum-cron.lock
+LOCKFILE=$LOCKDIR/pidfile
+TSLOCK=$LOCKDIR/ts.lock
+
+# Grab config settings
+if [ -f /etc/sysconfig/yum-cron ]; then
+ source /etc/sysconfig/yum-cron
+fi
+# set default for SYSTEMNAME
+[ -z "$SYSTEMNAME" ] && SYSTEMNAME=$(hostname)
+
+# Only run on certain days of the week
+dow=`date +%w`
+DAYS_OF_WEEK=${DAYS_OF_WEEK:-0123456}
+if [ "${DAYS_OF_WEEK/$dow/}" == "${DAYS_OF_WEEK}" ]; then
+ exit 0
+fi
+
+# if DOWNLOAD_ONLY is set then we force CHECK_ONLY too.
+# Gotta check before one can download!
+if [ "$DOWNLOAD_ONLY" == "yes" ]; then
+ CHECK_ONLY=yes
+fi
+
+YUMTMP=$(mktemp /var/run/yum-cron.XXXXXX)
+touch $YUMTMP
+[ -x /sbin/restorecon ] && /sbin/restorecon $YUMTMP
+
+# Random wait function
+random_wait() {
+ sleep $(( $RANDOM % ($RANDOMWAIT * 60) + 1 ))
+}
+
+# Note - the lockfile code doesn't try and use YUMTMP to email messages nicely.
+# Too many ways to die, this gets handled by normal cron error mailing.
+# Try mkdir for the lockfile, will test for and make it in one atomic action
+if mkdir $LOCKDIR 2>/dev/null; then
+ # store the current process ID in there so we can check for staleness later
+ echo "$$" >"${LOCKFILE}"
+ # and clean up locks and tempfile if the script exits or is killed
+ trap "{ rm -f $LOCKFILE $TSLOCK; rmdir $LOCKDIR 2>/dev/null; rm -f $YUMTMP; exit 255; }" INT TERM EXIT
+else
+ # lock failed, check if process exists. First, if there's no PID file
+ # in the lock directory, something bad has happened, we can't know the
+ # process name, so clean up the old lockdir and restart
+ if [ ! -f $LOCKFILE ]; then
+ rmdir $LOCKDIR 2>/dev/null
+ echo "yum-cron: no lock PID, clearing and restarting myself" >&2
+ exec $0 "$@"
+ fi
+ OTHERPID="$(cat "${LOCKFILE}")"
+ # if cat wasn't able to read the file anymore, another instance probably is
+ # about to remove the lock -- exit, we're *still* locked
+ if [ $? != 0 ]; then
+ echo "yum-cron: lock failed, PID ${OTHERPID} is active" >&2
+ exit 0
+ fi
+ if ! kill -0 $OTHERPID &>/dev/null; then
+ # lock is stale, remove it and restart
+ echo "yum-cron: removing stale lock of nonexistant PID ${OTHERPID}" >&2
+ rm -rf "${LOCKDIR}"
+ echo "yum-cron: restarting myself" >&2
+ exec $0 "$@"
+ else
+ # Remove stale (more than a day old) lockfiles
+ find $LOCKDIR -type f -name 'pidfile' -amin +1440 -exec rm -rf $LOCKDIR \;
+ # if it's still there, it wasn't too old, bail
+ if [ -f $LOCKFILE ]; then
+ # lock is valid and OTHERPID is active - exit, we're locked!
+ echo "yum-cron: lock failed, PID ${OTHERPID} is active" >&2
+ exit 0
+ else
+ # lock was invalid, restart
+ echo "yum-cron: removing stale lock belonging to stale PID ${OTHERPID}" >&2
+ echo "yum-cron: restarting myself" >&2
+ exec $0 "$@"
+ fi
+ fi
+fi
+
+# Then check for updates and/or do them, as configured
+{
+ # First, if this is CLEANDAY, do so
+ CLEANDAY=${CLEANDAY:-0}
+ if [ ! "${CLEANDAY/$dow/}" == "${CLEANDAY}" ]; then
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $WEEKLYSCRIPT
+ fi
+
+ # Now continue to do the real work
+ if [ "$CHECK_ONLY" == "yes" ]; then
+ random_wait
+ touch $TSLOCK
+ /usr/bin/yum $YUM_PARAMETER -e 0 -d 0 -y check-update 1> /dev/null 2>&1
+ case $? in
+ 1) exit 1;;
+ 100) echo "New updates available for host `/bin/hostname`";
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y -C check-update
+ if [ "$DOWNLOAD_ONLY" == "yes" ]; then
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y --downloadonly update
+ echo "Updates downloaded, use \"yum -C update\" manually to install them."
+ fi
+ ;;
+ esac
+ elif [ "$CHECK_FIRST" == "yes" ]; then
+ # Don't run if we can't access the repos
+ random_wait
+ touch $TSLOCK
+ /usr/bin/yum $YUM_PARAMETER -e 0 -d 0 check-update 2>&-
+ case $? in
+ 1) exit 1;;
+ 100) /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y update yum
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $DAILYSCRIPT
+ ;;
+ esac
+ else
+ random_wait
+ touch $TSLOCK
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y update yum
+ /usr/bin/yum $YUM_PARAMETER -e ${ERROR_LEVEL:-0} -d ${DEBUG_LEVEL:-0} -y shell $DAILYSCRIPT
+ fi
+} >> $YUMTMP 2>&1
+
+if [ ! -z "$MAILTO" ] && [ -x /bin/mail ]; then
+# if MAILTO is set, use mail command (ie better than standard mail with cron output)
+ [ -s "$YUMTMP" ] && mail -s "System update: $SYSTEMNAME" $MAILTO < $YUMTMP
+else
+# default behavior is to use cron's internal mailing of output from cron-script
+ cat $YUMTMP
+fi
+rm -f $YUMTMP
+
+exit 0
diff --git a/yum-cron/yum-cron.sysconfig b/yum-cron/yum-cron.sysconfig
new file mode 100644
index 0000000..930341c
--- /dev/null
+++ b/yum-cron/yum-cron.sysconfig
@@ -0,0 +1,58 @@
+# Pass any given paramter to yum, as run in all the scripts invoked
+# by this package. Be aware that this is global, and yum is invoked in
+# several modes by these scripts for which your own parameter might not
+# be appropriate
+YUM_PARAMETER=
+
+# Don't install, just check (valid: yes|no)
+CHECK_ONLY=no
+
+# Check to see if you can reach the repos before updating (valid: yes|no)
+CHECK_FIRST=no
+
+# Don't install, just check and download (valid: yes|no)
+# Implies CHECK_ONLY=yes (gotta check first to see what to download)
+DOWNLOAD_ONLY=no
+
+# Error level, practical range 0-10, 0 means print only critical errors which
+# you must be told, 1 means print all errors, even ones that are not important
+# Level 0 is the default
+# ERROR_LEVEL=0
+
+# Debug level, practical range 0-10, higher number means more output
+# Level 1 is a useful level if you want to see what's been done and
+# don't want to read /var/log/yum.log
+# Level 0 is the default
+# DEBUG_LEVEL=1
+
+# randomwait is used by yum to wait random time
+# default is 60 so yum waits random time from 1 to 60 minutes
+# the value must not be zero
+RANDOMWAIT="60"
+
+# if MAILTO is set and the mail command is available, the mail command
+# is used to deliver yum output
+
+# by default MAILTO is unset, so crond mails the output by itself
+# example: MAILTO=root
+MAILTO=
+
+# you may set SYSTEMNAME if you want your yum emails tagged differently
+# default is output of hostname command
+# this variable is used only if MAILTO is set too
+#SYSTEMNAME=""
+
+# you may set DAYS_OF_WEEK to the days of the week you want to run
+# default is every day
+#DAYS_OF_WEEK="0123456"
+
+# which day should it do cleanup on? defaults to 0 (Sunday). If this day isn't in the
+# DAYS_OF_WEEK above, it'll never happen
+CLEANDAY="0"
+
+# set to yes to make the yum-cron service to wait for transactions to complete
+SERVICE_WAITS=yes
+
+# set maximum time period (in seconds) for the yum-cron service to wait for
+# transactions to complete. The default is 300 seconds (5 minutes)
+SERVICE_WAIT_TIME=300
diff --git a/yum-cron/yum-cron.sysvinit b/yum-cron/yum-cron.sysvinit
new file mode 100755
index 0000000..63c5ec0
--- /dev/null
+++ b/yum-cron/yum-cron.sysvinit
@@ -0,0 +1,102 @@
+#!/bin/bash
+#
+# yum-cron This shell script enables the automatic use of YUM
+#
+# Author: Seth Vidal <skvidal at phy.duke.edu>
+#
+# chkconfig: - 50 01
+#
+# description: Enable daily run of yum, a program updater.
+# processname: yum-cron
+# config: /etc/yum/yum-daily.yum
+#
+
+# source function library
+. /etc/rc.d/init.d/functions
+
+test -f /etc/sysconfig/yum-cron && . /etc/sysconfig/yum-cron
+
+lockfile=/var/lock/subsys/yum-cron
+tslock=/var/lock/yum-cron.lock/ts.lock
+yumcronpid=/var/lock/yum-cron.lock/pidfile
+
+RETVAL=0
+
+start() {
+ echo -n $"Enabling nightly yum update: "
+ touch "$lockfile" && success || failure
+ RETVAL=$?
+ echo
+}
+
+stop() {
+ echo -n $"Disabling nightly yum update: "
+ if [ -f "$yumcronpid" -a "$SERVICE_WAITS" = "yes" ]; then
+ yum_done=0
+ if [ ! -f $tslock ]; then
+ # No transaction yet in progress, just kill it
+ kill `cat $yumcronpid > /dev/null 2>&1` > /dev/null 2>&1
+ yum_done=1
+ fi
+ if [ $yum_done -eq 0 ]; then
+ echo -n $"Waiting for yum "
+ if [ -z "$SERVICE_WAIT_TIME" ]; then
+ SERVICE_WAIT_TIME=300
+ fi
+ start=`date +%s`
+ end=`expr $start + $SERVICE_WAIT_TIME`
+ while [ `date +%s` -le $end ]
+ do
+ sleep 5
+ if [ ! -f "$tslock" ]; then
+ yum_done=1
+ break
+ fi
+ done
+ if [ $yum_done -eq 1 ]; then
+ echo -n " ok "
+ else
+ echo -n " failed "
+ fi
+ fi
+ fi
+ rm -f "$lockfile" && success || failure
+ RETVAL=$?
+ echo
+}
+
+restart() {
+ stop
+ start
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart|force-reload)
+ restart
+ ;;
+ reload)
+ ;;
+ condrestart)
+ [ -f "$lockfile" ] && restart
+ ;;
+ status)
+ if [ -f $lockfile ]; then
+ echo $"Nightly yum update is enabled."
+ RETVAL=0
+ else
+ echo $"Nightly yum update is disabled."
+ RETVAL=3
+ fi
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
+ exit 1
+esac
+
+exit $RETVAL
commit abdf7bf4113bfc6cf1ca64614ecfc05a22a452c7
Author: James Antill <james at and.org>
Date: Thu Jul 28 17:17:20 2011 -0400
Add top level make target for apidocs
diff --git a/Makefile b/Makefile
index 740b616..820e251 100644
--- a/Makefile
+++ b/Makefile
@@ -38,6 +38,10 @@ install:
for d in $(SUBDIRS); do make PYTHON=$(PYTHON) DESTDIR=`cd $(DESTDIR); pwd` -C $$d install; [ $$? = 0 ] || exit 1; done
+apidocs:
+ make -C docs/sphinxdocs html
+ echo "Docs are in: docs/sphinxdocs/_build/*"
+
.PHONY: docs test
DOCS = yum rpmUtils callback.py yumcommands.py shell.py output.py cli.py utils.py\
More information about the Yum-commits
mailing list