#!/bin/sh -T pb=$0 [ -z "$(echo "${pb}" | sed 's![^/]!!g')" ] && \ pb=$(type "$pb" | sed 's/^.* //g') pb=$(realpath $(dirname $pb)) pb=${pb%%/scripts} . ${pb}/scripts/lib/tinderlib.sh #rm -f ${pb}/builds/*/lock >/dev/null 2>&1 SLEEPTIME=30 MAXJOBS=2 LOGFILE=/var/log/tinderd.log trap "" 1 if [ ! -z "$LOGFILE" ]; then exec > $LOGFILE 2>&1 fi getbuild() { for b in `$pb/scripts/tc listBuildPortsQueue -s ENQUEUED -r | cut -d: -f3`; do if [ ! -e $pb/builds/$b/lock ]; then echo $b return fi done } getprocesses() { #ps afxww | grep tinderbuild | grep -v grep | wc -l | xargs echo find $pb/builds -name lock | wc -l | xargs echo } while true; do portslist="" nports="0" build=`getbuild` processes=`getprocesses` find $pb/builds -name lock | wc -l | xargs echo $pb/scripts/tc reorgBuildPortsQueue while [ -z "$build" -o "$processes" -ge "$MAXJOBS" ]; do if [ -z "$build" ]; then echo "===> Nothing to do, sleeping $SLEEPTIME secs" else echo "===> Already running $processes builds, sleeping $SLEEPTIME secs" fi sleep $SLEEPTIME build=`getbuild` processes=`getprocesses` done echo "===> Current build: $build" for entry in `$pb/scripts/tc listBuildPortsQueue -b $build -s ENQUEUED -r`; do id=`echo $entry | cut -d: -f1` port=`echo $entry | cut -d: -f4` $pb/scripts/tc updateBuildPortsQueueEntryStatus -i "$id" -s SUCCESS echo "===> Discovered port to build: $port" portslist="$portslist $port" nports=$(($nports+1)) $pb/scripts/tc addPort -b "$build" -d "$port" done echo "===> Building $nports port(s)" $pb/scripts/tc tinderbuild -nullfs -noduds -onceonly -b "$build" $portslist & sleep $SLEEPTIME done