[buildd-tools-devel] Bug#776438: example script for cron-driven sbuild-update

Christian Kastner debian at kvr.at
Tue Jan 27 23:26:34 UTC 2015


Source: sbuild
Version: 0.65.0-1
Severity: wishlist
Tags: patch

Hi,

I have attached the script I use to periodically update my various
sbuild chroots. It slightly facilitates chroot selection, logging, and
concurrency issues.

If you find this useful, please feel free to include it in examples/.

Regards,
Christian
-------------- next part --------------
#!/bin/sh
# Example script for automatically updating sbuild chroots
#
# Simply create a crontab /etc/cron.d/sbuild-update-all and specify the
# schedule that you want to use. The behaviour of this script can be influenced
# by the following evironment variables:
#
#   PATTERN     glob pattern to match the chroot config name against, in
#               directory /etc/schroot/chroot.d/.
#
#               Default: *-sbuild
#
#   UPDATEARGS  The arguments with which sbuild-update will be invoked.
#
#               Default: --update --dist-upgrade --autoclean --autoremove
#
#   LOGFILE     Log file to write to. These files are not rotated, you must set
#               this up yourself. See logrotate(8)
#
#               Default: /var/log/sbuild-update-all.log
#
# This script will refuse to run if another instance of it is running. In fact,
# it will refuse to run if there is an active chroot session (regardless of
# whether it is related to the matched patterns or not). Care for this must be
# taken when scheduling cron jobs, as crontabs are processed sequentially (with
# regards to variable assignment), but jobs are executed in parallel. 
#
# Examples
# ========
#
# 1. Update all sbuild chroots four times a day (at 00:15/06:15/12:15/18:15):
#
#     15 */6 * * * root /usr/share/doc/sbuild/examples/sbuild-update-all
#
# 2. Update all sid sbuild chroots daily, and all jessie sbuild chroots weekly,
#    and log the latter to a separate file:
#
#     PATTERN = sid-*-sbuild
#     @daily    root /usr/share/doc/sbuild/examples/sbuild-update-all
#
#     PATTERN = jessie-*-sbuild
#     LOGFILE = /var/log/wheezy-chroot-update.log
#     @weekly   root /usr/share/doc/sbuild/examples/sbuild-update-all
#
# The following will NOT work. Both of these jobs are executed at 00:15, so
# the second one will refuse to run:
#
#     PATTERN = foo-*
#     15 0  * * * root /usr/share/doc/sbuild/examples/sbuild-update-all
#
#     PATTERN = bar-*
#     15 0  * * * root /usr/share/doc/sbuild/examples/sbuild-update-all


# Output of sbuild-update invocations will be written to this file
LOGFILE=${LOGFILE:-/var/log/sbuild-update-all.log}

# Arguments passed to sbuild-update
UPDATEARGS=${UPDATEARGS:-"--update --dist-upgrade --autoclean --autoremove"}

# chroot config names are identified by this pattern
PATTERN=${PATTERN:-*-sbuild}


# Open logfile for output, make sure we're the only instance active
exec 8>>$LOGFILE
if ! flock -x -n 8
then
	echo "$0: another instance is already running"
	exit 1
fi
# Redirect stdout to logfile
exec 9>&1
exec 1>&8

if ! ls /etc/schroot/chroot.d/$PATTERN >/dev/null 2>&1
then
	echo "No chroots defined"
	break
fi

for fullname in /etc/schroot/chroot.d/$PATTERN
do
	confname=`basename $fullname`
    
	# Check for *any* active session and skip if there is one.
	# chroots can share common factors, for example an LVM volume, so it's
	# better to be safe than sorry.
	if  [ -n "`schroot -l --all-sessions`" ]
	then
		echo "Active schroot session, will not continue"
		break
	fi

	echo "****** `date` ******"
	echo "Action: sbuild-update $UPDATEARGS $confname"

	if ! sbuild-update $UPDATEARGS $confname
	then
		echo "ERROR: failed to update $confname"
		continue
	fi
done

# Release lock and undo redirections
exec 8>&- 1>&9 9>&-


More information about the Buildd-tools-devel mailing list