diff options
author | Holger Levsen <holger@layer-acht.org> | 2017-05-02 16:52:27 +0200 |
---|---|---|
committer | Holger Levsen <holger@layer-acht.org> | 2017-05-02 16:52:27 +0200 |
commit | 1872900adf2df32858625955c5bf904d51823e57 (patch) | |
tree | c4adff2999f8ac138f47e1c4d3026bd8f940b1b9 /bin/cgi-bin/nph-logwatch | |
parent | 055f9b1e21e169e5ab92a40421bf4b1b35abfca9 (diff) | |
download | jenkins.debian.net-1872900adf2df32858625955c5bf904d51823e57.tar.xz |
reproducible Debian: use Apache's NPH cgi mechanism to display growing logfiles. Thanks to Axel Beckert for telling me about NPH…
Signed-off-by: Holger Levsen <holger@layer-acht.org>
Diffstat (limited to 'bin/cgi-bin/nph-logwatch')
-rwxr-xr-x | bin/cgi-bin/nph-logwatch | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/bin/cgi-bin/nph-logwatch b/bin/cgi-bin/nph-logwatch new file mode 100755 index 00000000..e3e230e2 --- /dev/null +++ b/bin/cgi-bin/nph-logwatch @@ -0,0 +1,70 @@ +#!/bin/bash + +# Copyright © 2017 Holger Levsen (holger@layer-acht.org) +# released under the GPLv=2 + +set -e + +echo "HTTP/1.0 200 OK" +echo "Connection: close" +echo 'Content-type: text/plain; charset="utf-8"' +echo "" + +TARGET=${QUERY_STRING} + +# +# sanitize input +# +WORKER=$(basename $(dirname $TARGET)) +BUILD=$(basename $TARGET) + +# +# we only work on known files… +# +DIR=/var/lib/jenkins/userContent/reproducible/debian/build_service/$WORKER +FILE=$DIR/$BUILD/console.log + +# keep commented code for debugging… +if [ ! -d $DIR ] ; then + echo "$DIR does not exist." + #echo "Wanted $TARGET but $DIR does not exist." + exit 0 +elif [ ! -f $FILE ] ; then + echo "$FILE does not exist." + #echo "Wanted $TARGET but $FILE does not exist." + exit 0 +fi + +# +# this build exists, what about this one: +# +let NEW_BUILD=$BUILD+1 + +# +# if this ain't the latest build, just cat it's logfile +# +if [ -e $DIR/$NEW_BUILD/console.log ] ; then + cat $FILE +# +# if the worker ain't running, just cat the logfile +# +elif [ ! -z "$(ps fax|grep -v grep|grep 'reproducible_worker $WORKER.sh ')" ] ; then + cat $FILE +# +# FIXME: we should really just convert 'latest' into a number here and use the tail below… +# +elif [ "$BUILD" = "latest" ] ; then + cat $FILE +else + # + # else, we tail the logfile and kill the tail process, once the next build + # has been started + # + tail -c +0 -f $FILE & + TAILPID=$! + while ! test -f $DIR/$NEW_BUILD/console.log ; do + sleep 1 + done + kill -9 $TAILPID +fi +echo |