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
|
#!/usr/bin/env bash
set -uexo pipefail
usage() { echo "Usage: $(basename "$0")"; }
misuse() { usage 1>&2; exit 2; }
await-file()
(
local target="$1"
set +x
while ! test -e "$target"; do sleep 0.1; done
)
tk_pid=''
tmpdir=''
on-exit()
{
if test "$tk_pid"; then
kill "$tk_pid"
status=0
wait "$tk_pid" || status=$?
set +x
echo tk exited with status "$status (143 is likely)" 1>&2
set -x
fi
rm -rf "$tmpdir"
}
trap on-exit EXIT
test $# -eq 0 || misuse
tmpdir="$(mktemp -d "test-signal-handling-XXXXXX")"
tmpdir="$(cd "$tmpdir" && pwd)"
# Start the test server, which repeatedly writes to the configured
# target file, and make sure the target changes after a config file
# change and signal.
target_1="$tmpdir/target-1"
target_2="$tmpdir/target-2"
cat > "$tmpdir/config.json" <<EOS
{"signal-test-target": "$target_1"}
EOS
./tk -cp "$(pwd)/test" -- \
--config "$tmpdir/config.json" \
-b <(echo puppetlabs.trapperkeeper.signal-handling-test/signal-handling-test-service) &
tk_pid=$!
await-file "$target_1"
test exciting = "$(< "$target_1")"
test ! -e "$target_2"
cat > "$tmpdir/config.json" <<EOS
{"signal-test-target": "$target_2"}
EOS
kill -HUP "$tk_pid"
await-file "$target_2"
test exciting = "$(< "$target_2")"
|