Merge #210: bitcoind: postStart wait until bitcoind can receive rpc calls

02853067a1 bitcoind: postStart wait until bitcoind can receive rpc calls (nixbitcoin)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK 02853067a1

Tree-SHA512: 601b04957a26853c04d768b074006f0716edb131698afde2afb94cb0c862dddb745b93ef39ed014f95a01545eb60d370fd82201d0a898c7dac4c19622d25dafe
This commit is contained in:
Jonas Nick 2020-07-21 13:26:40 +00:00
commit 6856b8cb42
No known key found for this signature in database
GPG Key ID: 4861DBF262123605

View File

@ -260,8 +260,8 @@ in {
default = cfg.cli-nonetns-exec; default = cfg.cli-nonetns-exec;
description = "Binary to connect with the bitcoind instance."; description = "Binary to connect with the bitcoind instance.";
}; };
# Needed because bitcoind-import-banlist already executes inside # Needed because bitcoin-cli commands executed through systemd already
# nb-bitcoind, hence it doesn't need netns-exec prefixed. # run inside nb-bitcoind, hence they don't need netns-exec prefixed.
cli-nonetns-exec = mkOption { cli-nonetns-exec = mkOption {
readOnly = true; readOnly = true;
type = types.package; type = types.package;
@ -303,10 +303,11 @@ in {
install -o '${cfg.user}' -g '${cfg.group}' -m 640 <(echo "$cfg") $confFile install -o '${cfg.user}' -g '${cfg.group}' -m 640 <(echo "$cfg") $confFile
fi fi
''; '';
# Wait until RPC port is open. This usually takes just a few ms.
postStart = '' postStart = ''
while ! { exec 3>/dev/tcp/127.0.0.1/${toString cfg.rpc.port}; } &>/dev/null; do cd ${cfg.cli-nonetns-exec}/bin
sleep 0.05 # Poll until bitcoind accepts commands. This can take a long time.
while ! ./bitcoin-cli getnetworkinfo &> /dev/null; do
sleep 1
done done
''; '';
serviceConfig = nix-bitcoin-services.defaultHardening // { serviceConfig = nix-bitcoin-services.defaultHardening // {
@ -331,10 +332,6 @@ in {
after = [ "bitcoind.service" ]; after = [ "bitcoind.service" ];
script = '' script = ''
cd ${cfg.cli-nonetns-exec}/bin cd ${cfg.cli-nonetns-exec}/bin
# Poll until bitcoind accepts commands. This can take a long time.
while ! ./bitcoin-cli getnetworkinfo &> /dev/null; do
sleep 1
done
echo "Importing node banlist..." echo "Importing node banlist..."
cat ${./banlist.cli.txt} | while read line; do cat ${./banlist.cli.txt} | while read line; do
if ! err=$(eval "$line" 2>&1) && [[ $err != *already\ banned* ]]; then if ! err=$(eval "$line" 2>&1) && [[ $err != *already\ banned* ]]; then