bitcoind: postStart wait until bitcoind can receive rpc calls

This commit is contained in:
nixbitcoin 2020-07-21 10:08:24 +00:00
parent aad0fe6e45
commit 02853067a1
No known key found for this signature in database
GPG Key ID: DD11F9AD5308B3BA

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