Changeset View
Changeset View
Standalone View
Standalone View
contrib/teamcity/ibd.sh
#!/bin/bash | #!/bin/bash | ||||
set -euo pipefail | set -euo pipefail | ||||
### | ### | ||||
# Initial Block Download script. | # Initial Block Download script. | ||||
# | # | ||||
# Runs a bitcoind process until initial block download is complete. | # Runs a bitcoind process until initial block download is complete. | ||||
# Forwards the exit code from bitcoind onward. | # Forwards the exit code from bitcoind onward. | ||||
### | ### | ||||
MYPID=$$ | MYPID=$$ | ||||
# Setup | # Setup | ||||
mkdir -p ibd | DATA_DIR="ibd" | ||||
touch ibd/debug.log | mkdir -p "${DATA_DIR}" | ||||
DEBUG_LOG="${DATA_DIR}/debug.log" | |||||
touch "${DEBUG_LOG}" | |||||
chmod +x bitcoind | chmod +x bitcoind | ||||
# Launch bitcoind using this script's parameters | # Launch bitcoind using this script's parameters | ||||
./bitcoind -datadir=ibd $* & | ./bitcoind "-datadir=${DATA_DIR}" $* & | ||||
BITCOIND_PID=$! | BITCOIND_PID=$! | ||||
cleanup() { | cleanup() { | ||||
# Cleanup background processes spawned by this script. | # Cleanup background processes spawned by this script. | ||||
pkill -P ${MYPID} tail || true | pkill -P ${MYPID} tail || true | ||||
} | } | ||||
trap "cleanup" EXIT | trap "cleanup" EXIT | ||||
# Show some progress | # Show some progress | ||||
tail -f ibd/debug.log | grep 'UpdateTip' | awk 'NR % 10000 == 0' & | tail -f "${DEBUG_LOG}" | grep 'UpdateTip' | awk 'NR % 10000 == 0' & | ||||
# 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 | # 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 "${DEBUG_LOG}" | grep -m 1 'progress=1.000000' | ||||
) | ) | ||||
echo "Initial block download complete." | echo "Initial block download complete." | ||||
# TODO Add more checks to see if IBD completed as expected, | # TODO Add more checks to see if IBD completed as expected, | ||||
# These checks will exit the subshell with a non-zero exit code. | # These checks will exit the subshell with a non-zero exit code. | ||||
) & | ) & | ||||
IBD_PID=$! | IBD_PID=$! | ||||
Show All 27 Lines |