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 | 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 | |||||
cleanup() { | cleanup() { | ||||
echo "Terminating (pid: ${1})" | |||||
pkill -P ${MYPID} tail || true | pkill -P ${MYPID} tail || true | ||||
} | } | ||||
trap "cleanup" EXIT | |||||
# Launch bitcoind using this script's parameters | # Launch bitcoind using this script's parameters | ||||
./bitcoind -datadir=ibd $* & | ./bitcoind -datadir=ibd $* & | ||||
bitcoin_pid=$! | bitcoin_pid=$! | ||||
trap "cleanup ${bitcoin_pid}" EXIT | |||||
# Wait for IBD to finish and kill the daemon | # Wait for IBD to finish and kill the daemon | ||||
( | ( | ||||
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." | echo "Initial block download complete, killing bitcoin daemon (PID: ${bitcoin_pid})." | ||||
kill ${bitcoin_pid} | kill ${bitcoin_pid} | ||||
) & | ) & | ||||
# Show some progress | # Show some progress | ||||
tail -f ibd/debug.log | grep 'UpdateTip' | awk 'NR % 10000 == 0' & | tail -f ibd/debug.log | grep 'UpdateTip' | awk 'NR % 10000 == 0' & | ||||
# Wait for bitcoind to exit | # Wait for bitcoind to exit | ||||
wait ${bitcoin_pid} | wait ${bitcoin_pid} | ||||
exit $? | exit $? |