From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QfEqG-0000OI-9y for garchives@archives.gentoo.org; Fri, 08 Jul 2011 17:27:52 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C7BF021C023; Fri, 8 Jul 2011 17:27:44 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 5E26A21C023 for ; Fri, 8 Jul 2011 17:27:43 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 677DB2AC0F0 for ; Fri, 8 Jul 2011 17:27:42 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id CBD9C8003D for ; Fri, 8 Jul 2011 17:27:41 +0000 (UTC) From: "Liam McLoughlin" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Liam McLoughlin" Message-ID: <240a321b053dfd244b696ab2b456e1c264c9456a.hexxeh@gentoo> Subject: [gentoo-commits] proj/gentoaster:master commit in: / X-VCS-Repository: proj/gentoaster X-VCS-Files: client.php create_image.sh daemon.php status.php X-VCS-Directories: / X-VCS-Committer: hexxeh X-VCS-Committer-Name: Liam McLoughlin X-VCS-Revision: 240a321b053dfd244b696ab2b456e1c264c9456a Date: Fri, 8 Jul 2011 17:27:41 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: b63305804808148bfbb2ff269aea9e57 commit: 240a321b053dfd244b696ab2b456e1c264c9456a Author: Liam McLoughlin hexxeh net> AuthorDate: Fri Jul 8 17:26:05 2011 +0000 Commit: Liam McLoughlin hexxeh net> CommitDate: Fri Jul 8 17:26:05 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoaster.gi= t;a=3Dcommit;h=3D240a321b Added more robust error handling (we're not going to zombie onwards now w= hen things fail) Return codes and messages are now making it into a database, and job hand= les 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 @@ =20 echo "Sending job\n"; =20 - do { - $result =3D $client->do("invoke_image_build", file_get_contents("confi= gs/minimal.ini")); - switch($client->returnCode()) { - case GEARMAN_WORK_DATA: - break; - case GEARMAN_WORK_STATUS: - list($numerator, $denominator)=3D $client->doStatus(); - $progress =3D 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 =3D $client->doBackground("invoke_image_build", file_get_conten= ts("configs/crashtest.ini")); + $handlehash =3D md5($handle); =20 - while($client->returnCode() !=3D GEARMAN_SUCCESS); + echo "Job sent, handle was ".$handle." - hash ".$handlehash."\n"; =20 + $db =3D 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 # Prerequisites: extlinux, qemu-img, sfdisk =20 +# Early error handling (we'll override this later) + +handle_error() { + echo $1 + exit 1 +} + # Do some sanity checks first if [ "$(id -u)" !=3D "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 n= ot installed." =20 # Figure out where we are RUNNING_DIRECTORY=3D$(cd `dirname $0` && pwd) @@ -28,12 +34,11 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" =20 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 us= ing the --config flag" fi =20 # 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" =20 # Generate a few helper variables using the configuration file =20 @@ -51,18 +56,6 @@ PORTAGE_URL=3D"http://distribution.hexxeh.net/gentoo/p= ortage-latest.tar.bz2" BINHOST_URL=3D"http://tinderbox.dev.gentoo.org/default-linux/x86" EMERGE_PROXY=3D"${FLAGS_proxy}" =20 -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=3D$(( 512*63*255 )) -CYLINDERS=3D$(( ${IMAGE_BYTES}/${BYTES_PER_CYLINDER} )) -REAL_IMAGE_BYTES=3D$(( (${CYLINDERS}+1)*${BYTES_PER_CYLINDER} )) -echo "Step 2: Creating image ${IMAGE_NAME}, size ${REAL_IMAGE_BYTES} byt= es" -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"=20 + 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 dire= ctory" +cd ${IMAGE_WORK_PATH} +echo "" > ${LOG_FILE} || handle_error "Error creating log file" cleanup_mounts =20 +# Create disk iamge +BYTES_PER_CYLINDER=3D$(( 512*63*255 )) +CYLINDERS=3D$(( ${IMAGE_BYTES}/${BYTES_PER_CYLINDER} )) +REAL_IMAGE_BYTES=3D$(( (${CYLINDERS}+1)*${BYTES_PER_CYLINDER} )) +echo "Step 2: Creating image ${IMAGE_NAME}, size ${REAL_IMAGE_BYTES} byt= es" +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=3D1 count=3D2 seek=3D510 of=3D${IMAGE_NAME} c= onv=3Dnotrunc &>> ${LOG_FILE} LOOP_DEV_IMAGE=3D`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" =20 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 imag= e loop device" =20 # Mounting new root and boot echo "Step 4: Creating filesystems" =20 LOOP_DEV_BOOT=3D`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 mounti= ng boot partition" +mkfs -t ext2 ${LOOP_DEV_BOOT} &>> ${LOG_FILE} || handle_error "Error for= matting boot filesystem" sleep 2 -losetup -d ${LOOP_DEV_BOOT} +losetup -d ${LOOP_DEV_BOOT} || handle_error "Error destroying boot parti= tion loop device" =20 LOOP_DEV_ROOT=3D`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 loo= p mounting root partition" +mkfs -t ext3 ${LOOP_DEV_ROOT} &>> ${LOG_FILE} || handle_error "Error for= matting root filesystem" sleep 2 -losetup -d ${LOOP_DEV_ROOT} +losetup -d ${LOOP_DEV_ROOT} || handle_error "Error destroying root parti= tion loop device" =20 LOOP_DEV_SWAP=3D`losetup -f` -losetup -o $(( ( 512 * 2048 ) + ( ${BOOT_MEGABYTES} * 1024 * 1024 ) )) -= -sizelimit $(( ${SWAP_MEGABYTES} * 1024 * 1024 )) ${LOOP_DEV_SWAP} ${IMAG= E_NAME} +losetup -o $(( ( 512 * 2048 ) + ( ${BOOT_MEGABYTES} * 1024 * 1024 ) )) -= -sizelimit $(( ${SWAP_MEGABYTES} * 1024 * 1024 )) ${LOOP_DEV_SWAP} ${IMAG= E_NAME} || handle_error "Error loop mounting swap partition" mkswap ${LOOP_DEV_SWAP} &>> ${LOG_FILE} sleep 2=20 -losetup -d ${LOOP_DEV_SWAP} +losetup -d ${LOOP_DEV_SWAP} || handle_error "Error destroying swap parti= tion loop device" =20 echo "Step 5: Mounting fileystems" =20 mkdir -p rootfs -mount -o loop,offset=3D$(( ( 512 * 2048 ) + ( ${BOOT_MEGABYTES} * 1024 = * 1024 ) + ( ${SWAP_MEGABYTES} * 1024 * 1024 ) )) ${IMAGE_NAME} rootfs +mount -o loop,offset=3D$(( ( 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=3D$(( 512 * 2048 )) ${IMAGE_NAME} rootfs/boot +mount -o loop,offset=3D$(( 512 * 2048 )) ${IMAGE_NAME} rootfs/boot || ha= ndle_error "Error mounting boot filesystem" cd rootfs =20 # 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 =20 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" =20 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 &>> ${LO= G_FILE} + wget ${PORTAGE_URL} -O ${TOOL_RES_PATH}/portage-latest.tar.bz2 &>> ${LO= G_FILE} || handle_error "Error downloading Portage snapshot" fi =20 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} || handl= e_error "Error extracting Portage snapshot" =20 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" =20 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 tes= ting 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 "Er= ror 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" =20 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" =20 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" =20 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 =20 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" =20 echo "Step 19: Processing packages list" for PACKAGE in ${PACKAGES_LIST}; do echo "Installing ${PACKAGE}" &>> ${LOG_FILE} - linux32 chroot . emerge --jobs=3D${NUM_JOBS} ${PACKAGE} &>> ${LOG_FILE} + linux32 chroot . emerge --jobs=3D${NUM_JOBS} ${PACKAGE} &>> ${LOG_FILE}= || handle_error "Error emerging ${PACKAGE}" done =20 echo "Step 20: Adding default user" -linux32 chroot . useradd -g users -G lp,wheel,audio,cdrom,portage -m ${D= EFAULT_USERNAME} -linux32 chroot . /bin/bash -c "echo '${DEFAULT_USERNAME}:${DEFAULT_PASSW= ORD}' | chpasswd" &>> ${LOG_FILE} +linux32 chroot . useradd -g users -G lp,wheel,audio,cdrom,portage -m ${D= EFAULT_USERNAME} || handle_error "Error adding default user" +linux32 chroot . /bin/bash -c "echo '${DEFAULT_USERNAME}:${DEFAULT_PASSW= ORD}' | chpasswd" &>> ${LOG_FILE} || handle_error "Error setting default = user password" =20 if [[ ${OUTPUT_FORMAT} =3D "vbox" ]] then echo "Installing VirtualBox additions/drivers" - linux32 chroot . emerge xf86-video-virtualbox xf86-input-virtualbox vir= tualbox-guest-additions &>> ${LOG_FILE} + linux32 chroot . emerge xf86-video-virtualbox xf86-input-virtualbox vir= tualbox-guest-additions &>> ${LOG_FILE} || handle_error "Error emerging V= irtualBox 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 =20 echo "Step 22: Installing extlinux" -extlinux --heads 255 --sectors 63 --install boot &>> ${LOG_FILE} -dd if=3D/usr/lib/extlinux/mbr.bin of=3D../${IMAGE_NAME} conv=3Dnotrunc &= >> ${LOG_FILE} -cp ${TOOL_RES_PATH}/extlinux.conf boot/ +extlinux --heads 255 --sectors 63 --install boot &>> ${LOG_FILE} || hand= le_error "Error installing extlinux" +dd if=3D/usr/lib/extlinux/mbr.bin of=3D../${IMAGE_NAME} conv=3Dnotrunc &= >> ${LOG_FILE} || handle_error "Error copying extlinux MBR" +cp ${TOOL_RES_PATH}/extlinux.conf boot/ || handle_error "Error copying e= xtlinux 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=3D"${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_erro= r "Error converting disk image to VMDK format" rm -rf ${IMAGE_NAME} IMAGE_OUT=3D"${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 "Erro= r moving finished image" +mv ${LOG_FILE} ${IMAGES_OUTPUT_PATH}/${BUILD_ID}.log || handle_error "Er= ror moving log file" +rm -rf ${IMAGE_WORK_PATH} || handle_error "Error removing working direct= ory" =20 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()); =20 + function update_result($handle, $returncode, $result) { + $result =3D trim($result); + echo "A job finished with return code ".$returncode.": ".$result."\n"; + $db =3D mysql_connect("localhost","gentoaster",""); + if(!$db) die("Could not connect to database ".mysql_error()); + mysql_select_db("gentoaster"); + mysql_query("UPDATE builds SET result =3D '".mysql_real_escape_string(= $result)."', returncode =3D '".$returncode."' WHERE handle =3D '".mysql_r= eal_escape_string($handle)."'"); + return serialize(array($returncode, $result)); + } + function image_build($job) { global $configurations_path, $gentoaster_path, $tool_name, $progress_m= agic; =20 - echo "Got job ID ".$job->handle(). "(".md5($job->handle()).")\n"; + $handle =3D $job->handle(); + $handlehash =3D md5($handle); + + echo "Processing job handle hash ".$handlehash."\n"; =20 $configuration_string =3D $job->workload(); $configuration_array =3D parse_ini_string($configuration_string); =20 - if($configuration_array !=3D=3D FALSE) { + if($configuration_array !=3D=3D FALSE && isset($configuration_array["B= UILD_ID"])) { $build_id =3D $configuration_array["BUILD_ID"]; $build_path =3D $configurations_path."/".$build_id; - mkdir($build_path); + @mkdir($build_path, 0777, true); =20 if(is_writable($build_path)) { chdir($build_path); file_put_contents("config.ini", $configuration_string); $tool_args =3D "--config config.ini --cachedkernel"; - $process_handle =3D popen($gentoaster_path."/".$tool_name." ".$tool_= args, "r"); + $process_handle =3D popen($gentoaster_path."/".$tool_name." ".$tool_= args." 2>&1", "r"); =20 $nonstatus_output =3D ""; =20 @@ -47,14 +60,14 @@ } } =20 - pclose($process_handle); + $returncode =3D pclose($process_handle); =20 - 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 writ= able"); } } else { - echo "Configuration string is not valid"; + return update_result($handle, -3, "Configuration string is not valid"= ); } } =20 diff --git a/status.php b/status.php new file mode 100644 index 0000000..37db751 --- /dev/null +++ b/status.php @@ -0,0 +1,29 @@ +addServer(); + + $status =3D $client->jobStatus($handle); + if($status[0]) { + echo "Running: " . ($status[1] ? "true" : "false") . ", progress: " .= ceil($status[2]/$status[3]*100) . "%, numerator: " . $status[2] . ", den= omintor: " . $status[3] . "\n"; + } else { + $result =3D mysql_query("SELECT returncode, result FROM builds WHERE = id =3D '".mysql_real_escape_string($argv[1])."'"); + $jobres =3D mysql_fetch_array($result); + if($jobres[0] !=3D NULL) { + echo "Job returned with code ".$jobres[0].": ".$jobres[1]."\n"; + } else { + echo "Job failed\n"; + } + } + } else { + echo "Invalid handle hash\n"; + } + +?>