public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Liam McLoughlin" <hexxeh@hexxeh.net>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoaster:master commit in: /
Date: Fri,  8 Jul 2011 17:27:41 +0000 (UTC)	[thread overview]
Message-ID: <240a321b053dfd244b696ab2b456e1c264c9456a.hexxeh@gentoo> (raw)

commit:     240a321b053dfd244b696ab2b456e1c264c9456a
Author:     Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net>
AuthorDate: Fri Jul  8 17:26:05 2011 +0000
Commit:     Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net>
CommitDate: Fri Jul  8 17:26:05 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoaster.git;a=commit;h=240a321b

Added more robust error handling (we're not going to zombie onwards now when things fail)

Return codes and messages are now making it into a database, and job handles are mapped to handle hashes to prevent job hijacking

---
 client.php      |   28 +++--------
 create_image.sh |  132 ++++++++++++++++++++++++++++++------------------------
 daemon.php      |   29 +++++++++---
 status.php      |   29 ++++++++++++
 4 files changed, 131 insertions(+), 87 deletions(-)

diff --git a/client.php b/client.php
index 0110d3b..b289a34 100644
--- a/client.php
+++ b/client.php
@@ -8,26 +8,14 @@
 
 	echo "Sending job\n";
 
-	do {
-		$result = $client->do("invoke_image_build", file_get_contents("configs/minimal.ini"));
-		switch($client->returnCode()) {
-			case GEARMAN_WORK_DATA:
-				break;
-			case GEARMAN_WORK_STATUS:
-				list($numerator, $denominator)= $client->doStatus();
-				$progress = ceil($numerator/$denominator*100);
-				echo "Status: $progress% complete\n";
-      				break;
-    			case GEARMAN_SUCCESS:
-      				echo "Job finished!\n";
-      				echo $result;
-      				break;
-    			default:
-      				echo "Return code: " . $client->returnCode() . "\n";
-      				exit;
-  		}
-	}
+	$handle = $client->doBackground("invoke_image_build", file_get_contents("configs/crashtest.ini"));
+	$handlehash = md5($handle);
 
-	while($client->returnCode() != GEARMAN_SUCCESS);
+	echo "Job sent, handle was ".$handle." - hash ".$handlehash."\n";
 
+	$db = mysql_connect("localhost","gentoaster","");
+	if(!$db) die("Could not connect to database ".mysql_error());
+	mysql_select_db("gentoaster");
+	mysql_query("INSERT INTO builds (id, handle) VALUES('".$handlehash."','".$handle."')");
+	echo "Job handle mapping added to database\n";
 ?>

diff --git a/create_image.sh b/create_image.sh
index 3cee693..d70cda5 100755
--- a/create_image.sh
+++ b/create_image.sh
@@ -5,14 +5,20 @@
 # Usage: ./create_image.sh <configuration file path>
 # Prerequisites: extlinux, qemu-img, sfdisk
 
+# Early error handling (we'll override this later)
+
+handle_error() {
+	echo $1
+	exit 1
+}
+
 # Do some sanity checks first
 if [ "$(id -u)" != "0" ]; then
-   echo "Gentoaster must run with root permissions!" 1>&2
-   exit 1
+   handle_error "Gentoaster must run with root permissions!"
 fi
-hash qemu-img 2>&- || { echo >&2 "Gentoaster requires qemu-img, but it's not installed."; exit 1; }
-hash extlinux 2>&- || { echo >&2 "Gentoaster requires extlinux, but it's not installed."; exit 1; }
-hash sfdisk 2>&- || { echo >&2 "Gentoaster requires sfdisk, but it's not installed."; exit 1; }
+hash qemu-img 2>&- || handle_error "Gentoaster requires qemu-img, but it's not installed."
+hash extlinux 2>&- || handle_error "Gentoaster requires extlinux, but it's not installed."
+hash sfdisk 2>&- || handle_error "Gentoaster requires sfdisk, but it's not installed."
 
 # Figure out where we are
 RUNNING_DIRECTORY=$(cd `dirname $0` && pwd)
@@ -28,12 +34,11 @@ FLAGS "$@" || exit 1
 eval set -- "${FLAGS_ARGV}"
 
 if [ -z ${FLAGS_config} ]; then
-	echo  >&2 "Gentoaster requires a valid configuration to be passed using the --config flag"
-	exit 1
+	handle_error "Gentoaster requires a valid configuration to be passed using the --config flag"
 fi
 
 # Parse the configuration we took as an arg
-source ${RUNNING_DIRECTORY}/parse_config.sh ${FLAGS_config}
+source ${RUNNING_DIRECTORY}/parse_config.sh ${FLAGS_config} 2>/dev/null || handle_error "Error parsing build configuration"
 
 # Generate a few helper variables using the configuration file
 
@@ -51,18 +56,6 @@ PORTAGE_URL="http://distribution.hexxeh.net/gentoo/portage-latest.tar.bz2"
 BINHOST_URL="http://tinderbox.dev.gentoo.org/default-linux/x86"
 EMERGE_PROXY="${FLAGS_proxy}"
 
-echo "Step 1: Creating build working directory"
-mkdir -p ${IMAGE_WORK_PATH}
-cd ${IMAGE_WORK_PATH}
-echo "" > ${LOG_FILE}
-
-# Create disk iamge
-BYTES_PER_CYLINDER=$(( 512*63*255 ))
-CYLINDERS=$(( ${IMAGE_BYTES}/${BYTES_PER_CYLINDER} ))
-REAL_IMAGE_BYTES=$(( (${CYLINDERS}+1)*${BYTES_PER_CYLINDER} ))
-echo "Step 2: Creating image ${IMAGE_NAME}, size ${REAL_IMAGE_BYTES} bytes"
-qemu-img create -f raw ${IMAGE_NAME} ${REAL_IMAGE_BYTES} &>> ${LOG_FILE}
-
 # Clean up old mounts
 cleanup_mounts() {
 	sleep 2
@@ -74,13 +67,34 @@ cleanup_mounts() {
 	umount -d -f ${IMAGE_WORK_PATH}/rootfs &>> ${LOG_FILE}
 	sleep 2
 }
+
+# Handle some errors
+handle_error() {
+	echo "$1" 
+	cd ${IMAGE_WORK_PATH}
+	cleanup_mounts
+	rm -rf ${IMAGE_WORK_PATH}
+	exit 1
+}
+
+echo "Step 1: Creating build working directory"
+mkdir -p ${IMAGE_WORK_PATH} || handle_error "Error creating working directory"
+cd ${IMAGE_WORK_PATH}
+echo "" > ${LOG_FILE} || handle_error "Error creating log file"
 cleanup_mounts
 
+# Create disk iamge
+BYTES_PER_CYLINDER=$(( 512*63*255 ))
+CYLINDERS=$(( ${IMAGE_BYTES}/${BYTES_PER_CYLINDER} ))
+REAL_IMAGE_BYTES=$(( (${CYLINDERS}+1)*${BYTES_PER_CYLINDER} ))
+echo "Step 2: Creating image ${IMAGE_NAME}, size ${REAL_IMAGE_BYTES} bytes"
+qemu-img create -f raw ${IMAGE_NAME} ${REAL_IMAGE_BYTES} &>> ${LOG_FILE} || handle_error "Error creating disk image file"
+
 # Create partition table
 echo "Step 3: Writing partition table"
 echo -e "\x55\xaa" | dd bs=1 count=2 seek=510 of=${IMAGE_NAME} conv=notrunc &>> ${LOG_FILE}
 LOOP_DEV_IMAGE=`losetup -f`
-losetup --sizelimit ${REAL_IMAGE_BYTES} ${LOOP_DEV_IMAGE} ${IMAGE_NAME} &>> ${LOG_FILE}
+losetup --sizelimit ${REAL_IMAGE_BYTES} ${LOOP_DEV_IMAGE} ${IMAGE_NAME} &>> ${LOG_FILE} || handle_error "Error loop mounting disk image"
 
 sfdisk ${LOOP_DEV_IMAGE} -H64 -S32 &>> ${LOG_FILE} << EOF
 1,${BOOT_MEGABYTES},83,*
@@ -88,35 +102,35 @@ $(( 1+ ${BOOT_MEGABYTES} )),${SWAP_MEGABYTES},82,-
 $(( 1+ ${BOOT_MEGABYTES} + ${SWAP_MEGABYTES} )),${ROOT_MEGABYTES},83,-
 EOF
 sleep 2
-losetup -d ${LOOP_DEV_IMAGE}
+losetup -d ${LOOP_DEV_IMAGE} || handle_error "Error destroying disk image loop device"
 
 # Mounting new root and boot
 echo "Step 4: Creating filesystems"
 
 LOOP_DEV_BOOT=`losetup -f`
-losetup -o $(( 512 * 2048 )) --sizelimit $(( ${BOOT_MEGABYTES} * 1024 * 1024 )) ${LOOP_DEV_BOOT} ${IMAGE_NAME}
-mkfs -t ext2 ${LOOP_DEV_BOOT} &>> ${LOG_FILE}
+losetup -o $(( 512 * 2048 )) --sizelimit $(( ${BOOT_MEGABYTES} * 1024 * 1024 )) ${LOOP_DEV_BOOT} ${IMAGE_NAME} || handle_error "Error loop mounting boot partition"
+mkfs -t ext2 ${LOOP_DEV_BOOT} &>> ${LOG_FILE} || handle_error "Error formatting boot filesystem"
 sleep 2
-losetup -d ${LOOP_DEV_BOOT}
+losetup -d ${LOOP_DEV_BOOT} || handle_error "Error destroying boot partition loop device"
 
 LOOP_DEV_ROOT=`losetup -f`
-losetup -o $(( ( 512 * 2048 )  + ( ${BOOT_MEGABYTES} * 1024 * 1024 ) + ( ${SWAP_MEGABYTES} * 1024 * 1024 ) )) --sizelimit $(( ${ROOT_MEGABYTES} * 1024 * 1024 )) ${LOOP_DEV_ROOT} ${IMAGE_NAME}
-mkfs -t ext3 ${LOOP_DEV_ROOT} &>> ${LOG_FILE}
+losetup -o $(( ( 512 * 2048 )  + ( ${BOOT_MEGABYTES} * 1024 * 1024 ) + ( ${SWAP_MEGABYTES} * 1024 * 1024 ) )) --sizelimit $(( ${ROOT_MEGABYTES} * 1024 * 1024 )) ${LOOP_DEV_ROOT} ${IMAGE_NAME} || handle_error "Error loop mounting root partition"
+mkfs -t ext3 ${LOOP_DEV_ROOT} &>> ${LOG_FILE} || handle_error "Error formatting root filesystem"
 sleep 2
-losetup -d ${LOOP_DEV_ROOT}
+losetup -d ${LOOP_DEV_ROOT} || handle_error "Error destroying root partition loop device"
 
 LOOP_DEV_SWAP=`losetup -f`
-losetup -o $(( ( 512 * 2048 ) + ( ${BOOT_MEGABYTES} * 1024 * 1024 ) )) --sizelimit $(( ${SWAP_MEGABYTES} * 1024 * 1024 )) ${LOOP_DEV_SWAP} ${IMAGE_NAME}
+losetup -o $(( ( 512 * 2048 ) + ( ${BOOT_MEGABYTES} * 1024 * 1024 ) )) --sizelimit $(( ${SWAP_MEGABYTES} * 1024 * 1024 )) ${LOOP_DEV_SWAP} ${IMAGE_NAME} || handle_error "Error loop mounting swap partition"
 mkswap ${LOOP_DEV_SWAP} &>> ${LOG_FILE}
 sleep 2 
-losetup -d ${LOOP_DEV_SWAP}
+losetup -d ${LOOP_DEV_SWAP} || handle_error "Error destroying swap partition loop device"
 
 echo "Step 5: Mounting fileystems"
 
 mkdir -p rootfs
-mount -o loop,offset=$(( ( 512 * 2048 )  + ( ${BOOT_MEGABYTES} * 1024 * 1024 ) + ( ${SWAP_MEGABYTES} * 1024 * 1024 ) )) ${IMAGE_NAME} rootfs
+mount -o loop,offset=$(( ( 512 * 2048 )  + ( ${BOOT_MEGABYTES} * 1024 * 1024 ) + ( ${SWAP_MEGABYTES} * 1024 * 1024 ) )) ${IMAGE_NAME} rootfs  || handle_error "Error mounting root filesystem"
 mkdir -p rootfs/boot
-mount -o loop,offset=$(( 512 * 2048 )) ${IMAGE_NAME} rootfs/boot
+mount -o loop,offset=$(( 512 * 2048 )) ${IMAGE_NAME} rootfs/boot || handle_error "Error mounting boot filesystem"
 cd rootfs
 
 # Setup Gentoo
@@ -124,27 +138,27 @@ cd rootfs
 if [ ! -f ${TOOL_RES_PATH}/stage3.tar.bz2 ];
 then
 	echo "Downloading Stage 3"
-	wget ${STAGE3_URL} -O ${TOOL_RES_PATH}/stage3.tar.bz2 &>> ${LOG_FILE}
+	wget ${STAGE3_URL} -O ${TOOL_RES_PATH}/stage3.tar.bz2 &>> ${LOG_FILE} || handle_error "Error downloading Stage3 tarball"
 fi
 
 echo "Step 6: Extracting Stage 3"
-tar jxf ${TOOL_RES_PATH}/stage3.tar.bz2 &>> ${LOG_FILE}
+tar jxf ${TOOL_RES_PATH}/stage3.tar.bz2 &>> ${LOG_FILE} || handle_error "Error extracting Stage3 tarball"
 
 if [ ! -f ${TOOL_RES_PATH}/portage-latest.tar.bz2 ];
 then
 	echo "Downloading Portage snapshot"
-	wget ${PORTAGE_URL} -O ${TOOL_RES_PATH}/portage-latest.tar.bz2 &>> ${LOG_FILE}
+	wget ${PORTAGE_URL} -O ${TOOL_RES_PATH}/portage-latest.tar.bz2 &>> ${LOG_FILE} || handle_error "Error downloading Portage snapshot"
 fi
 
 echo "Step 7: Extracting Portage snapshot"
 cd usr
-tar jxf ${TOOL_RES_PATH}/portage-latest.tar.bz2 &>> ${LOG_FILE}
+tar jxf ${TOOL_RES_PATH}/portage-latest.tar.bz2 &>> ${LOG_FILE} || handle_error "Error extracting Portage snapshot"
 
 echo "Step 8: Setting up chroot"
 cd ..
-mount -t proc /proc proc
-mount --rbind /dev dev
-cp -L /etc/resolv.conf etc/resolv.conf
+mount -t proc /proc proc || handle_error "Error mounting /proc"
+mount --rbind /dev dev || handle_error "Error mounting /dev"
+cp -L /etc/resolv.conf etc/resolv.conf || handle_error "Error setting up resolv.conf"
 
 echo "Step 9: Setting up make.conf"
 mkdir -p usr/portage/packages
@@ -193,40 +207,40 @@ echo "Step 17: Setting up kernel"
 # If we got the flag, used a cached kernel to reduce build times for testing
 if [[ ${FLAGS_cachedkernel} -eq ${FLAGS_TRUE} ]]; then
 	echo "Using cached kernel" &>> ${LOG_FILE}
-	cp ${TOOL_RES_PATH}/bzImage boot/kernel
-	cp -R ${TOOL_RES_PATH}/kernelmodules/* lib/modules/
+	cp ${TOOL_RES_PATH}/bzImage boot/kernel || handle_error "Error copying cached kernel"
+	cp -R ${TOOL_RES_PATH}/kernelmodules/* lib/modules/ || handle_error "Error copying cached kernel modules"
 else
 	echo "Downloading/installing kernel sources" &>> ${LOG_FILE}
-	linux32 chroot . emerge gentoo-sources &>> ${LOG_FILE}
+	linux32 chroot . emerge gentoo-sources &>> ${LOG_FILE} || handle_error "Error emerging kernel sources"
 
 	echo "Copying kernel configuration" &>> ${LOG_FILE}
-	cp ${TOOL_RES_PATH}/kernelconfig usr/src/linux/.config
+	cp ${TOOL_RES_PATH}/kernelconfig usr/src/linux/.config || handle_error "Error copying kernel config"
 
 	echo "Building kernel" &>> ${LOG_FILE}
-	linux32 chroot . make -C /usr/src/linux -j${NUM_JOBS} &>> ${LOG_FILE}
+	linux32 chroot . make -C /usr/src/linux -j${NUM_JOBS} &>> ${LOG_FILE} || handle_error "Error building kernel"
 
 	echo "Installing kernel" &>> ${LOG_FILE}
-	linux32 chroot . make -C /usr/src/linux modules_install &>> ${LOG_FILE}
-	usr/src/linux/arch/i386/boot/bzImage boot/kernel &>> ${LOG_FILE}
+	linux32 chroot . make -C /usr/src/linux modules_install &>> ${LOG_FILE} || handle_error "Error installing kernel modules"
+	cp usr/src/linux/arch/i386/boot/bzImage boot/kernel &>> ${LOG_FILE} || handle_error "Error copying kernel"
 fi
 
 echo "Step 18: Setting root password"
-linux32 chroot . /bin/bash -c "echo 'root:${ROOT_PASSWORD}' | chpasswd" &>> ${LOG_FILE}
+linux32 chroot . /bin/bash -c "echo 'root:${ROOT_PASSWORD}' | chpasswd" &>> ${LOG_FILE} || handle_error "Error setting root password"
 
 echo "Step 19: Processing packages list"
 for PACKAGE in ${PACKAGES_LIST}; do
 	echo "Installing ${PACKAGE}" &>> ${LOG_FILE}
-	linux32 chroot . emerge --jobs=${NUM_JOBS} ${PACKAGE} &>> ${LOG_FILE}
+	linux32 chroot . emerge --jobs=${NUM_JOBS} ${PACKAGE} &>> ${LOG_FILE} || handle_error "Error emerging ${PACKAGE}"
 done
 
 echo "Step 20: Adding default user"
-linux32 chroot . useradd -g users -G lp,wheel,audio,cdrom,portage -m ${DEFAULT_USERNAME}
-linux32 chroot . /bin/bash -c "echo '${DEFAULT_USERNAME}:${DEFAULT_PASSWORD}' | chpasswd" &>> ${LOG_FILE}
+linux32 chroot . useradd -g users -G lp,wheel,audio,cdrom,portage -m ${DEFAULT_USERNAME} || handle_error "Error adding default user"
+linux32 chroot . /bin/bash -c "echo '${DEFAULT_USERNAME}:${DEFAULT_PASSWORD}' | chpasswd" &>> ${LOG_FILE} || handle_error "Error setting default user password"
 
 if [[ ${OUTPUT_FORMAT} = "vbox" ]]
 then
 	echo "Installing VirtualBox additions/drivers"
-	linux32 chroot . emerge xf86-video-virtualbox xf86-input-virtualbox virtualbox-guest-additions &>> ${LOG_FILE}
+	linux32 chroot . emerge xf86-video-virtualbox xf86-input-virtualbox virtualbox-guest-additions &>> ${LOG_FILE} || handle_error "Error emerging VirtualBox extras"
 	linux32 chroot . rc-update add virtualbox-guest-additions default &>> ${LOG_FILE}
 	mv etc/X11/xorg.conf etc/X11/xorg.conf.bak &>> ${LOG_FILE}
 	linux32 chroot . usermod -a vboxguest ${DEFAULT_USERNAME}
@@ -239,9 +253,9 @@ fi
 sed -i '/MAKEOPTS/ d' etc/make.conf
 
 echo "Step 22: Installing extlinux"
-extlinux --heads 255 --sectors 63 --install boot &>> ${LOG_FILE}
-dd if=/usr/lib/extlinux/mbr.bin of=../${IMAGE_NAME} conv=notrunc &>> ${LOG_FILE}
-cp ${TOOL_RES_PATH}/extlinux.conf boot/
+extlinux --heads 255 --sectors 63 --install boot &>> ${LOG_FILE} || handle_error "Error installing extlinux"
+dd if=/usr/lib/extlinux/mbr.bin of=../${IMAGE_NAME} conv=notrunc &>> ${LOG_FILE} || handle_error "Error copying extlinux MBR"
+cp ${TOOL_RES_PATH}/extlinux.conf boot/ || handle_error "Error copying extlinux configuration"
 cd  ..
 cleanup_mounts
 case "${OUTPUT_FORMAT}" in
@@ -251,20 +265,20 @@ case "${OUTPUT_FORMAT}" in
 		;;
 	"vbox" )
 		echo "Converting image from RAW to VDI" &>> ${LOG_FILE}
-		qemu-img convert -O vdi ${IMAGE_NAME} ${BUILD_ID}.vdi
+		qemu-img convert -O vdi ${IMAGE_NAME} ${BUILD_ID}.vdi || handle_error "Error converting disk image to VDI format"
 		rm -rf ${IMAGE_NAME}
 		IMAGE_OUT="${BUILD_ID}.vdi"
 		;;
 	"vmware" )
 		echo "Converting image from RAW to VMDK" &>> ${LOG_FILE}
-		qemu-img convert -O vmdk ${IMAGE_NAME} ${BUILD_ID}.vmdk
+		qemu-img convert -O vmdk ${IMAGE_NAME} ${BUILD_ID}.vmdk || handle_error "Error converting disk image to VMDK format"
 		rm -rf ${IMAGE_NAME}
 		IMAGE_OUT="${BUILD_ID}.vmdk"
 		;;
 esac
-mv ${IMAGE_OUT} ${IMAGES_OUTPUT_PATH}/${IMAGE_OUT}
-mv ${LOG_FILE} ${IMAGES_OUTPUT_PATH}/${BUILD_ID}.log
-rm -rf ${IMAGE_WORK_PATH}
+mv ${IMAGE_OUT} ${IMAGES_OUTPUT_PATH}/${IMAGE_OUT} || handle_error "Error moving finished image"
+mv ${LOG_FILE} ${IMAGES_OUTPUT_PATH}/${BUILD_ID}.log || handle_error "Error moving log file"
+rm -rf ${IMAGE_WORK_PATH} || handle_error "Error removing working directory"
 
 echo "Step 23: Image build completed!"
 echo "Your image is here: ${IMAGES_OUTPUT_PATH}/${IMAGE_OUT}"

diff --git a/daemon.php b/daemon.php
index deeb0d6..a7090f5 100644
--- a/daemon.php
+++ b/daemon.php
@@ -16,24 +16,37 @@
 	$worker->addFunction("invoke_image_build", "image_build");
 	while ($worker->work());
 
+	function update_result($handle, $returncode, $result) {
+		$result = trim($result);
+		echo "A job finished with return code ".$returncode.": ".$result."\n";
+	        $db = mysql_connect("localhost","gentoaster","");
+        	if(!$db) die("Could not connect to database ".mysql_error());
+        	mysql_select_db("gentoaster");
+		mysql_query("UPDATE builds SET result = '".mysql_real_escape_string($result)."', returncode = '".$returncode."' WHERE handle = '".mysql_real_escape_string($handle)."'");
+		return serialize(array($returncode, $result));
+	}
+
 	function image_build($job) {
 		global $configurations_path, $gentoaster_path, $tool_name, $progress_magic;
 
-		echo "Got job ID ".$job->handle(). "(".md5($job->handle()).")\n";
+		$handle = $job->handle();
+		$handlehash = md5($handle);
+
+		echo "Processing job handle hash ".$handlehash."\n";
 
 		$configuration_string = $job->workload();
 		$configuration_array = parse_ini_string($configuration_string);
 
-		if($configuration_array !== FALSE) {
+		if($configuration_array !== FALSE && isset($configuration_array["BUILD_ID"])) {
 			$build_id = $configuration_array["BUILD_ID"];
 			$build_path = $configurations_path."/".$build_id;
-			mkdir($build_path);
+			@mkdir($build_path, 0777, true);
 
 			if(is_writable($build_path)) {
 				chdir($build_path);
 				file_put_contents("config.ini", $configuration_string);
 				$tool_args = "--config config.ini --cachedkernel";
-				$process_handle = popen($gentoaster_path."/".$tool_name." ".$tool_args, "r");
+				$process_handle = popen($gentoaster_path."/".$tool_name." ".$tool_args." 2>&1", "r");
 
 				$nonstatus_output = "";
 
@@ -47,14 +60,14 @@
 					}
 				}
 
-				pclose($process_handle);
+				$returncode = pclose($process_handle);
 
-				return $nonstatus_output;
+				return update_result($handle, $returncode, $nonstatus_output);
 			} else {
-				echo "Configured build path is not writable";
+				return update_result($handle, -2, "Configured build path is not writable");
 			}
 		} else {
-			echo "Configuration string is not valid";
+			return update_result($handle, -3, "Configuration string is not valid");
 		}
 	}
 

diff --git a/status.php b/status.php
new file mode 100644
index 0000000..37db751
--- /dev/null
+++ b/status.php
@@ -0,0 +1,29 @@
+<?php
+	if(!isset($argv[1])) die("No handle hash given\n");
+        $db = mysql_connect("localhost","gentoaster","");
+        if(!$db) die("Could not connect to database ".mysql_error()."\n");
+        mysql_select_db("gentoaster");
+        $result = mysql_query("SELECT handle FROM builds WHERE id = '".mysql_real_escape_string($argv[1])."'");
+	if(mysql_num_rows($result) == 1) {
+		$handles = mysql_fetch_array($result);
+		$handle = $handles[0];
+		$client = new GearmanClient();
+		$client->addServer();
+
+		$status = $client->jobStatus($handle);
+		if($status[0]) {
+			echo "Running: " . ($status[1] ? "true" : "false") . ", progress: " . ceil($status[2]/$status[3]*100) . "%, numerator: " . $status[2] . ", denomintor: " . $status[3] . "\n";
+		} else {
+			$result = mysql_query("SELECT returncode, result FROM builds WHERE id = '".mysql_real_escape_string($argv[1])."'");
+			$jobres = mysql_fetch_array($result);
+			if($jobres[0] != NULL) {
+				echo "Job returned with code ".$jobres[0].": ".$jobres[1]."\n";
+			} else {
+				echo "Job failed\n";
+			}
+		}
+	} else {
+		echo "Invalid handle hash\n";
+	}
+
+?>



             reply	other threads:[~2011-07-08 17:27 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-08 17:27 Liam McLoughlin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-08-23 21:29 [gentoo-commits] proj/gentoaster:master commit in: / Liam McLoughlin
2011-08-19 13:09 Liam McLoughlin
2011-08-15  2:24 Liam McLoughlin
2011-08-15  2:00 Liam McLoughlin
2011-08-15  1:54 Liam McLoughlin
2011-08-14 15:46 Liam McLoughlin
2011-08-12 23:18 Liam McLoughlin
2011-08-12 23:17 Liam McLoughlin
2011-08-12 23:17 Liam McLoughlin
2011-08-11 20:31 [gentoo-commits] proj/gentoaster:webui " Liam McLoughlin
2011-08-12 23:18 ` [gentoo-commits] proj/gentoaster:master " Liam McLoughlin
2011-07-15 20:41 [gentoo-commits] proj/gentoaster:webui " Liam McLoughlin
2011-08-12 23:17 ` [gentoo-commits] proj/gentoaster:master " Liam McLoughlin
2011-07-11 14:00 Liam McLoughlin
2011-07-10 23:53 Liam McLoughlin
2011-07-08 22:41 Liam McLoughlin
2011-07-08 18:47 Liam McLoughlin
2011-07-08 18:35 Liam McLoughlin
2011-07-08 18:27 Liam McLoughlin
2011-07-08  2:45 Liam McLoughlin
2011-06-16  1:01 Liam McLoughlin
2011-06-16  1:01 Liam McLoughlin
2011-06-14 21:28 Liam McLoughlin
2011-06-14 21:03 Liam McLoughlin
2011-06-14 20:44 Liam McLoughlin
2011-06-08  0:06 Liam McLoughlin
2011-06-05 23:32 Liam McLoughlin
2011-06-05 23:32 Liam McLoughlin
2011-06-05 23:32 Liam McLoughlin
2011-06-04  3:47 Liam McLoughlin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=240a321b053dfd244b696ab2b456e1c264c9456a.hexxeh@gentoo \
    --to=hexxeh@hexxeh.net \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox