Changeset View
Changeset View
Standalone View
Standalone View
contrib/teamcity/ibd.sh
Show All 10 Lines | |||||
MYPID=$$ | MYPID=$$ | ||||
# Setup | # Setup | ||||
mkdir -p ibd | mkdir -p ibd | ||||
touch ibd/debug.log | touch ibd/debug.log | ||||
chmod +x bitcoind | chmod +x bitcoind | ||||
# On shutdown, cleanup background processes spawned by this script | # Launch bitcoind using this script's parameters | ||||
./bitcoind -datadir=ibd $* & | |||||
BITCOIND_PID=$! | |||||
cleanup() { | cleanup() { | ||||
# Cleanup background processes spawned by this script. | |||||
pkill -P ${MYPID} tail || true | pkill -P ${MYPID} tail || true | ||||
} | } | ||||
trap "cleanup" EXIT | trap "cleanup" EXIT | ||||
# Launch bitcoind using this script's parameters | # Show some progress | ||||
./bitcoind -datadir=ibd $* & | tail -f ibd/debug.log | grep 'UpdateTip' | awk 'NR % 10000 == 0' & | ||||
bitcoin_pid=$! | |||||
# Wait for IBD to finish and kill the daemon | # Wait for IBD to finish and kill the daemon | ||||
( | ( | ||||
( | |||||
# Ignore the broken pipe when tail tries to write pipe closed by grep | |||||
set +o pipefail | set +o pipefail | ||||
tail -f ibd/debug.log | grep -m 1 'progress=1.000000' | tail -f ibd/debug.log | grep -m 1 'progress=1.000000' | ||||
echo "Initial block download complete, killing bitcoin daemon (PID: ${bitcoin_pid})." | ) | ||||
kill ${bitcoin_pid} | echo "Initial block download complete." | ||||
# TODO Add more checks to see if IBD completed as expected, | |||||
# These checks will exit the subshell with a non-zero exit code. | |||||
) & | ) & | ||||
IBD_PID=$! | |||||
# Show some progress | # When the IBD subshell finishes, kill bitcoind | ||||
tail -f ibd/debug.log | grep 'UpdateTip' | awk 'NR % 10000 == 0' & | ( | ||||
while [ -e /proc/${IBD_PID} ]; do sleep 0.1; done | |||||
echo "Cleaning up bitcoin daemon (PID: ${BITCOIND_PID})." | |||||
kill ${BITCOIND_PID} | |||||
) & | |||||
# Wait for bitcoind to exit | # Wait for bitcoind to exit, whether it exited on its own or IBD finished | ||||
wait ${bitcoin_pid} | wait ${BITCOIND_PID} | ||||
exit $? | BITCOIND_EXIT_CODE=$? | ||||
if [ "${BITCOIND_EXIT_CODE}" -ne "0" ]; then | |||||
echo "bitcoind exited unexpectedly with code: ${BITCOIND_EXIT_CODE}" | |||||
exit ${BITCOIND_EXIT_CODE} | |||||
fi | |||||
# Get the exit code for the IBD subshell, which should have exited already | |||||
wait ${IBD_PID} | |||||
IBD_EXIT_CODE=$? | |||||
# The IBD subshell should only exit with a non-zero code if one of the tests | |||||
# failed. | |||||
if [ "${IBD_EXIT_CODE}" -ne "0" ]; then | |||||
echo "IBD tests failed with code: ${IBD_EXIT_CODE}" | |||||
exit ${IBD_EXIT_CODE} | |||||
fi |