[Box Backup-commit] COMMIT r2967 - box/bitten/bitten-slave

subversion at boxbackup.org subversion at boxbackup.org
Fri Jun 10 10:37:55 BST 2011


Author: jamesog
Date: 2011-06-10 10:37:55 +0100 (Fri, 10 Jun 2011)
New Revision: 2967

Added:
   box/bitten/bitten-slave/README
Modified:
   box/bitten/bitten-slave/minion
Log:
 * Add README for Minion
 * General tidy-up of minion code, refactoring of function names
 * Check for bitten-slave on first run!
 * Add e-mail notifications for when bitten-slave dies
 * Add version checking against SVN
 * Add support for .minionrc, move Solaris-specific env variables out of minion


Added: box/bitten/bitten-slave/README
===================================================================
--- box/bitten/bitten-slave/README	                        (rev 0)
+++ box/bitten/bitten-slave/README	2011-06-10 09:37:55 UTC (rev 2967)
@@ -0,0 +1,63 @@
+Minion
+======
+
+Minion is a control script for bitten-slave written for the Box Backup project.
+On first run it will check that the build environment is sane (i.e. all
+requisite software is installed). This is to prevent false errors being sent to
+the build master. After this it simply acts as a wrapper to bitten-slave.
+
+Minion will read a file called .minionrc in the current directory. This file
+can contain environment variables that need to be present during the build.
+This is particularly recommended for Solaris where the stock OpenSSL cannot be
+used. For e.g.:
+
+  # Export variables needed for GCC on Solaris to avoid using the system
+  # OpenSSL. Change these to wherever your OpenSSL libs/headers are.
+  CFLAGS="-I/usr/local/include"
+  CXXFLAGS="-I/usr/local/include"
+  LDFLAGS="-L/usr/local/lib"
+  export CFLAGS CXXFLAGS LDFLAGS
+
+
+Required Software
+-----------------
+
+Python setuptools
+bitten-slave
+Subversion
+autoconf, automake
+gcc, g++
+OpenSSL libs/headers
+zlib libs/headers
+xsltproc
+Perl LWP::UserAgent (part of libwww)
+
+Optional Software
+-----------------
+
+curl
+
+bitten-slave installation
+-------------------------
+
+The bitten slave is packaged as a Python egg file. This can be installed with
+easy_install when setuptools is installed.
+
+Information about setuptools can be found at:
+http://pypi.python.org/pypi/setuptools
+
+The BittenSlave egg can be downloaded from:
+http://ftp.edgewall.com/pub/bitten/
+
+Ensure you only download BittenSlave and not Bitten. The build master currently
+runs version 0.6 so it is recommended to run the same version of the slave.
+
+Notifications
+-------------
+
+By default minion will send an e-mail to the user running it when the
+bitten-slave process exits. This can be disabled by setting NOTIFICATIONS in
+.minionrc to something other than "on", "true" or 1.
+
+If you wish to send notifications to a different address, set NOTIFY_ADDR in
+.minionrc.

Modified: box/bitten/bitten-slave/minion
===================================================================
--- box/bitten/bitten-slave/minion	2011-06-09 13:44:09 UTC (rev 2966)
+++ box/bitten/bitten-slave/minion	2011-06-10 09:37:55 UTC (rev 2967)
@@ -2,11 +2,17 @@
 #
 # minion - Wrapper script for bitten-slave for Box Backup
 #
+# $Rev$
+# $Author$
+# $Date$
+# $URL$
 
 TRAC_URL="https://www.boxbackup.org/trac/builds"
 LOG="-l bitten.log"
 WORK_DIR="build"
 SSH_ID="$HOME/.ssh/bitten-minion"
+VERSION=2
+NOTIFICATIONS=1
 
 # Need to export SSH_ID so it's passed down to bitten-slave
 export SSH_ID
@@ -14,87 +20,70 @@
 build_os=`uname -s | tr [A-Z] [a-z]`
 config="${build_os}.ini"
 
-# Func: chk_env
-# Desc: Checks that the build environment is suitable
-chk_env () {
-	echo "This looks like the first time you've run the bitten minion."
-	echo "I need to check a few things out first..."
-	echo
-	printf "Checking for Subversion... "
-	svn help >/dev/null 2>&1
-	if [ $? -eq 0 ]; then
-		echo "OK"
+# Func: CheckFor
+# Desc: Generic handler for environment checking
+CheckFor () {
+	local wanted chk_cmd sev err_msg rv
+	wanted=$1
+	chk_cmd=$2
+	case "$3" in
+		req) sev="ERROR" ;;
+		opt) sev="WARN" ;;
+		info) sev="INFO" ;;
+	esac
+	if [ -n "$4" ]; then
+		err_msg=`eval echo $4`
 	else
-		printf "\n  ==> ERROR: Subversion is missing.\n"
-		exit 1
+		err_msg="$wanted is missing"
 	fi
 
-	printf "Checking for autoconf... "
-	autoconf --help >/dev/null 2>&1
-	if [ $? -eq 0 ]; then
+	printf "Checking for $wanted... "
+	$chk_cmd >/dev/null 2>&1
+	rv=$?
+	if [ $rv -eq 0 ]; then
 		echo "OK"
+		echo "HAVE_${wanted}=yes" | tr [a-z] [A-Z] | \
+		sed -e 's/\+/X/g' -e 's/[^0-9A-Z=]/_/g' >> .minion_env
 	else
-		printf "\n  ==> ERROR: autoconf is missing.\n"
-		exit 1
+		printf "\n  ==> ${sev}: ${err_msg}.\n"
+		return $rv
 	fi
+}
 
-	printf "Checking for automake... "
-	automake --help >/dev/null 2>&1
-	if [ $? -eq 0 ]; then
-		echo "OK"
-	else
-		printf "\n  ==> ERROR: automake is missing.\n"
-		exit 1
-	fi
+# Func: CheckEnv
+# Desc: Checks that the build environment is suitable
+CheckEnv () {
+	echo "This looks like the first time you've run the bitten minion."
+	echo "I need to check a few things out first..."
+	echo
+	CheckFor "bitten-slave" "bitten-slave --version" "req" || {
+		CheckFor "setuptools" "easy_install --help" "req" || {
+			echo
+			echo "Neither bitten-slave nor setuptools are installed."
+			echo "Please see http://pypi.python.org/pypi/setuptools to install setuptools"
+			echo "then use easy_install to install the bitten slave."
+			exit 1
+		}
+	}
+	CheckFor "Subversion" "svn help" "req" || exit 1
+	CheckFor "autoconf" "autoconf --help" "req" || exit 1
+	CheckFor "automake" "automake --help" "req" || exit 1
+	CheckFor "gcc" "gcc -v" "req" || exit 1
+	CheckFor "g++" "g++ -v" "req" || exit 1
+	CheckFor "xsltproc" "xsltproc -V" "req" "\$wanted is missing. Please install libxml" || exit 1
+	CheckFor "LWP::UserAgent" "perl -MLWP::UserAgent -e ''" "req" "Perl module \$wanted is missing. Please install libwww" || exit 1
+	CheckFor "curl" "curl -V" "opt" "\$wanted is missing. I won\'t be able to check for version updates"
 
-	printf "Checking for gcc... "
-	gcc -v >/dev/null 2>&1
-	if [ $? -eq 0 ]; then
-		echo "OK"
-	else
-		printf "\n  ==> ERROR: gcc is missing.\n"
-		exit 1
-	fi
-
-	printf "Checking for g++... "
-	g++ -v >/dev/null 2>&1
-	if [ $? -eq 0 ]; then
-		echo "OK"
-	else
-		printf "\n  ==> ERROR: g++ is missing.\n"
-		exit 1
-	fi
-
-	printf "Checking for xsltproc... "
-	xsltproc -V >/dev/null 2>&1
-	if [ $? -eq 0 ]; then
-		echo "OK"
-	else
-		printf "\n  ==> ERROR: xsltproc is missing. Please install libxml.\n"
-		exit 1
-	fi
-
-	printf "Checking for LWP::UserAgent... "
-	perl -MLWP::UserAgent -e ''
-	if [ $? -eq 0 ]; then
-		echo "OK"
-	else
-		printf "\n  ==> ERROR: Perl module LWP::UserAgent is missing. Please install libwww.\n"
-		exit 1
-	fi
-
-	printf "Checking if SSH key exists... "
-	test -f $SSH_ID >/dev/null 2>&1
-	if [ $? -eq 0 ]; then
-		echo "OK"
-	else
-		printf "\n  ==> SSH key does not exist. Running ssh-keygen.\n"
+	CheckFor "SSH key" "test -f $SSH_ID" "info" "SSH key does not exist. Running ssh-keygen"
+	if [ $? -gt 0 ]; then
 		ssh-keygen -t rsa -f $SSH_ID -N ''
 		echo
 		echo "  ==> SSH key generated. Be sure to have the key uploaded to the build master!"
 	fi
 
 	echo
+	[ ! -f ${config} ] && GenConfig
+	echo
 	echo "All done! Binaries look fine, but make sure you have headers for the following:"
 	echo " - openssl"
 	echo " - zlib"
@@ -106,9 +95,9 @@
 	exit
 }
 
-# Func: chk_dist
+# Func: CheckLinuxDist
 # Desc: Attempts to work out which distribution of Linux we're on.
-chk_dist () {
+CheckLinuxDist () {
 	if [ -f /etc/redhat-release ]; then
 		dist_name=`cat /etc/redhat-release | perl -ne '/ release/;print $\`'`
 		dist_ver=`cat /etc/redhat-release | perl -ne '/release (\d+(\.\d+)?)/;print $1'`
@@ -134,9 +123,9 @@
 	fi
 }
 
-# Func: gen_config
+# Func: GenConfig
 # Desc: Creates a bitten-slave configuration file (INI format).
-gen_config () {
+GenConfig () {
 	# Back up any existing config before (re-)creating
 	[ -f ${config} ] && mv $config ${config}.old
 	if [ -f ${config}.old ]; then
@@ -172,31 +161,74 @@
   	
 	echo "Config generated as $config."
 	echo "Please set Trac user/pass in the [authentication] section."
-	exit
 }
 
+# Func: NotifyByEmail
+# Desc: Send an email when bitten-slave exits.
+NotifyByEmail () {
+	local bs_rc=$1
+	case "$NOTIFICATIONS" in
+		[Oo][Nn]|[Tt][Rr][Uu][Ee]|1) ;;
+		*) return ;;
+	esac
+	if [ -z "$NOTIFY_ADDR" ]; then
+		NOTIFY_ADDR=$USER
+	fi
+	local subject="`hostname`: bitten-slave terminated"
+	cat >/tmp/minionmsg <<EOF
+Message from minion on `hostname`:
+
+The bitten-slave has terminated with exit code: $bs_rc
+Please check and re-start minion.
+EOF
+	mailx -s "$subject" $NOTIFY_ADDR </tmp/minionmsg
+	rm /tmp/minionmsg
+}
+
+# Func: CheckVersion
+# Desc: Check for newer versions of minion.
+CheckVersion () {
+	if [ -n "$HAVE_CURL" ]; then
+		local URL=https://www.boxbackup.org/svn/box/bitten/bitten-slave/minion
+		local REPO_VER=`curl -s $URL | awk -F= '/^VERSION/ {print $2}'`
+		REPO_VER=${REPO_VER:=0}
+		if [ $VERSION -lt $REPO_VER ]; then
+			echo "==> Notice: An updated version is available. You have: $VERSION, available: $REPO_VER"
+			echo
+		fi
+	fi
+}
+
 case "$build_os" in
-	sunos)
-	  # Export variables needed for GCC on Solaris to avoid using the system
-	  # OpenSSL. Change these to wherever your OpenSSL libs/headers are.
-	  CFLAGS="-I/usr/local/include"
-	  CXXFLAGS="-I/usr/local/include"
-	  LDFLAGS="-L/usr/local/lib"
-	  export CFLAGS CXXFLAGS LDFLAGS
-	  ;;
 	linux)
 	  # If we're running a Linux variant, check and change config file name
-	  chk_dist
+	  CheckLinuxDist
 	  config="`echo $dist_name | tr [A-Z] [a-z]`.ini"
 	  ;;
 esac
 
-[ x"$1" = x"gen-config" ] && gen_config
+if [ x"$1" = x"gen-config" ]; then
+	GenConfig
+	exit
+fi
 
-[ ! -f .minion_env ] && chk_env
+if [ -f .minion_env ]; then
+	. ./.minion_env
+else
+	CheckEnv
+fi
 
+if [ -f ./.minionrc ]; then
+	. ./.minionrc
+fi
+
+CheckVersion
+
 if [ -f "${config}" ]; then
 	bitten-slave -f ${config} -d $WORK_DIR $LOG $* $TRAC_URL
+	# If we get to this point the slave has been terminated.
+	# Notify the admin, if enabled.
+	NotifyByEmail $?
 else
 	echo "Config file missing. Please re-run with gen-config option."
 	exit 1


Property changes on: box/bitten/bitten-slave/minion
___________________________________________________________________
Added: svn:keywords
   + Rev Date Author URL




More information about the Boxbackup-commit mailing list