summaryrefslogtreecommitdiffstats
path: root/bin/reproducible_worker.sh
blob: 99b597aef4bd246aad85b9e1ad75fb6709c0b4c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash

# Copyright © 2017 Holger Levsen (holger@layer-acht.org)
# released under the GPLv=2

set -e

WORKER_NAME=$1
NODE1=$2
NODE2=$3

# normally defined by jenkins and used by reproducible_common.sh
JENKINS_URL=https://jenkins.debian.net

DEBUG=false
. /srv/jenkins/bin/common-functions.sh
common_init "$@"

# common code defining db access
. /srv/jenkins/bin/reproducible_common.sh

# endless loop
while true ; do
	#
	# check if we really should be running
	#
	RUNNING=$(ps fax|grep -v grep|grep "$0 $1 ")
	if [ -z "$RUNNING" ] ; then
		echo "$(date --utc) - '$0 $1' already running, thus stopping this."
		break
	fi
	SERVICE="reproducible_build@startup.service"
	# try systemctl twice, but only output and thus log the 2nd attempt…
	RUNNING=$(systemctl show $SERVICE 2>/dev/null |grep ^SubState|cut -d "=" -f2)
	if [ "$RUNNING" != "running" ] ; then
		# sometimes systemctl requests time out… handle that gracefully
		sleep 23
		RUNNING=$(systemctl show $SERVICE|grep ^SubState|cut -d "=" -f2)
		if [ "$RUNNING" != "running" ] ; then
			echo "$(date --utc) - '$SERVICE' not running, thus stopping this."
			break
		fi
	fi

	# sleep up to 2.3 seconds (additionally to the random sleep reproducible_build.sh does anyway)
	/bin/sleep $(echo "scale=1 ; $(shuf -i 1-23 -n 1)/10" | bc )

	#
	# increment BUILD_ID
	#
	BUILD_BASE=/var/lib/jenkins/userContent/reproducible/debian/build_service/$WORKER_NAME
	OLD_ID=$(ls -1rt $BUILD_BASE|egrep -v "(latest|worker.log)" |sort -n|tail -1)
	let BUILD_ID=OLD_ID+1
	mkdir -p $BUILD_BASE/$BUILD_ID
	rm -f $BUILD_BASE/latest
	ln -sf $BUILD_ID $BUILD_BASE/latest

	#
	# prepare variables for export
	#
	export BUILD_URL=https://jenkins.debian.net/userContent/reproducible/debian/build_service/$WORKER_NAME/$BUILD_ID/
	export BUILD_ID=$BUILD_ID
	export JOB_NAME="reproducible_builder_$WORKER_NAME"
	export

	#
	# actually run reproducible_build.sh
	#
	echo
	echo "================================================================================================"
	echo "$(date --utc) - running build #$BUILD_ID for $WORKER_NAME on $NODE1 and $NODE2."
	echo "                               see https://tests.reproducible-builds.org/cgi-bin/nph-logwatch?$WORKER_NAME/$BUILD_ID"
	echo "================================================================================================"
	echo
	/srv/jenkins/bin/reproducible_build.sh $NODE1 $NODE2 >$BUILD_BASE/$BUILD_ID/console.log 2>&1
	echo
done