Files
bongo/contrib/testing/queue-store-concurrency-check.sh
2026-07-23 12:36:47 +02:00

95 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
#
# Coordinate the installed Store concurrency diagnostic with one real
# systemd restart. The diagnostic itself runs as the unprivileged Bongo user.
set -eu
user=${1:-stq06}
count=${BONGO_TEST_MESSAGE_COUNT:-24}
service=${BONGO_SERVICE:-bongo.service}
admin_tool=${BONGO_ADMIN_TOOL:-/usr/bin/bongo-admin}
queue_tool=${BONGO_QUEUE_TOOL:-/usr/bin/bongo-queuetool}
store_tool=${BONGO_STORE_TOOL:-/usr/bin/bongo-storetool}
run_as=${BONGO_TEST_RUN_AS:-bongo}
as_root=${BONGO_TEST_AS_ROOT:-sudo -n}
if [ "$(id -un)" = "$run_as" ]; then
as_bongo=
else
as_bongo="sudo -n -u $run_as"
fi
work=$(mktemp -d "${TMPDIR:-/tmp}/bongo-stq06.XXXXXX")
chmod 0777 "$work"
worker=
cleanup()
{
status=$?
if [ -n "$worker" ] && kill -0 "$worker" >/dev/null 2>&1; then
kill "$worker" >/dev/null 2>&1 || true
wait "$worker" >/dev/null 2>&1 || true
fi
$as_root /usr/bin/systemctl start "$service" >/dev/null 2>&1 || true
rm -rf "$work"
exit "$status"
}
trap cleanup EXIT HUP INT TERM
wait_for()
{
path=$1
attempts=$2
while [ "$attempts" -gt 0 ]; do
if [ -e "$path" ]; then
return 0
fi
if [ -n "$worker" ] && ! kill -0 "$worker" >/dev/null 2>&1; then
wait "$worker"
echo "STQ-06: worker exited before requesting restart" >&2
return 1
fi
attempts=$((attempts - 1))
sleep 1
done
echo "STQ-06: timed out waiting for $path" >&2
return 1
}
wait_services()
{
attempts=30
while [ "$attempts" -gt 0 ]; do
if $as_bongo "$queue_tool" list >/dev/null 2>&1 &&
$as_bongo "$store_tool" -u "$user" \
document-list /mail/INBOX >/dev/null 2>&1; then
return 0
fi
attempts=$((attempts - 1))
sleep 1
done
echo "STQ-06: Queue and Store did not become ready after restart" >&2
return 1
}
if ! $as_root "$admin_tool" user list | grep -Fx "$user" >/dev/null; then
$as_root "$admin_tool" user add "$user" >/dev/null
fi
$as_root /usr/bin/systemctl daemon-reload
$as_root /usr/bin/systemctl start "$service"
wait_services
$as_bongo "$store_tool" -u "$user" concurrency-check \
--work "$work" --count "$count" &
worker=$!
wait_for "$work/restart.ready" 60
$as_root /usr/bin/systemctl restart "$service"
wait_services
touch "$work/restart.done"
wait "$worker"
worker=