summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-03-21 12:25:20 +0100
committerErich Eckner <git@eckner.net>2018-03-21 12:25:20 +0100
commit47eb9a4ee2a93630dd9d8712b4ea7b3386029cf6 (patch)
tree9c7a31d065927f2f62cbb1119bb544e902357d2e /bin
parent28593a5108321b6c14262f96c322a3be12fee9ba (diff)
downloadbuilder-47eb9a4ee2a93630dd9d8712b4ea7b3386029cf6.tar.xz
bin/ping-from-slave new to send pings to buildmaster in regular intervals during a build
Diffstat (limited to 'bin')
-rwxr-xr-xbin/build-packages16
-rwxr-xr-xbin/ping-to-master39
2 files changed, 55 insertions, 0 deletions
diff --git a/bin/build-packages b/bin/build-packages
index c7b5f85..aa3de6d 100755
--- a/bin/build-packages
+++ b/bin/build-packages
@@ -258,6 +258,7 @@ while [ "${count}" -ne 0 ]; do
fi
cd "${base_dir}"
recursively_umount_and_rm "${tmp_dir}"
+ flock -u 9 || true
exit "${err}"
}
find "${work_dir}" \
@@ -371,6 +372,17 @@ while [ "${count}" -ne 0 ]; do
find . -maxdepth 1 -type f \( -name '*.pkg.tar.xz' -o -name '*.pkg.tar.xz.sig' \) -exec \
rm {} \;
+ echo 'building' > "${tmp_dir}/.ping-build-master"
+ if [ -z "${forced_package}" ]; then
+ # we get a lock on "${work_dir}/ping-build-master.lock",
+ # if we release that lock, ping-to-master should stop _immediately_
+ exec 9> "${work_dir}/ping-build-master.lock"
+ if ! flock -n 9; then
+ >&2 echo 'ERROR: Cannot lock ping-to-master - this should not happen.'
+ exit 2
+ fi
+ "${base_dir}/bin/ping-to-master" "$$" "${tmp_dir}" &
+ fi
>&2 printf '%s: building package "%s" (revisions %s %s, repository %s, straw %s) ...' \
"$(date +'%Y-%m-%d %T')" \
"${package}" \
@@ -390,6 +402,7 @@ while [ "${count}" -ne 0 ]; do
>&2 printf ' ok.\n'
tar_content_dir=$(mktemp -d "${tmp_dir}/tar-content.XXXXXX")
find . -maxdepth 1 -type f -name '*-debug-*.pkg.tar.xz*' -delete
+ echo 'post-build' > "${tmp_dir}/.ping-build-master"
>&2 printf 'signing package(s)\n'
find . -maxdepth 1 -type f -name '*.pkg.tar.xz' \
-execdir gpg --local-user="${package_key}" --detach-sign '{}' \; \
@@ -501,6 +514,7 @@ while [ "${count}" -ne 0 ]; do
fi
done
>&2 printf ' ok.\n'
+ echo 'uploading' > "${tmp_dir}/.ping-build-master"
if ${upload_to_build_master}; then
find "${tar_content_dir}/" -maxdepth 1 \
\( \
@@ -565,6 +579,7 @@ while [ "${count}" -ne 0 ]; do
success=true
break
fi
+ echo 'failure' > "${tmp_dir}/.ping-build-master"
>&2 printf ' failed.\n'
done
@@ -619,6 +634,7 @@ while [ "${count}" -ne 0 ]; do
# clean up tmp_dir
cd "${base_dir}"
recursively_umount_and_rm "${tmp_dir}"
+ flock -u 9 || true
trap - EXIT
continue
diff --git a/bin/ping-to-master b/bin/ping-to-master
new file mode 100755
index 0000000..15c9120
--- /dev/null
+++ b/bin/ping-to-master
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# periodically connects to the buildmaster to call ping-from slave to:
+# - report any update on the build process
+# - show that the build is still running
+# - get notified by the build master if the build is not necessary anymore
+
+# shellcheck source=conf/default.conf
+. "${0%/*}/../conf/default.conf"
+
+# TODO: abort build if requested to
+
+parent_pid="$1"
+parent_tmp_dir="$2"
+
+exec 9> "${work_dir}/ping-build-master.lock"
+
+while kill -0 "${parent_pid}" && \
+ [ -f "${parent_tmp_dir}/.ping-build-master" ]; do
+
+ # shellcheck disable=SC2029
+ find "${parent_tmp_dir}" \
+ -xdev \
+ -type f \
+ -name '*.build-log' \
+ -exec wc -l {} \; | \
+ sed 's, .*/, ,' | \
+ ssh \
+ -i "${master_build_server_identity}" \
+ -p "${master_build_server_port}" \
+ "${master_build_server_user}@${master_build_server}" \
+ 'ping-from-slave' "$(cat "${parent_tmp_dir}/.ping-build-master")"
+
+ # we wait upto 60 seconds to get the lock - if we get it, the parent
+ # must have released it and we're finished
+ if flock -w 60 9; then
+ break
+ fi
+done