banlist: don't wait in preStart until bitcoind is ready

preStart is meant for short-run scripts, but bitcoind can take a long
time until it accepts commands, especially on low-powered systems.

Fixes #122
This commit is contained in:
Erik Arvstedt 2019-11-12 19:40:33 +01:00
parent d87c50a305
commit d64156e485
No known key found for this signature in database
GPG Key ID: 33312B944DD97846

View File

@ -272,32 +272,18 @@ in {
wantedBy = [ "bitcoind.service" ];
bindsTo = [ "bitcoind.service" ];
after = [ "bitcoind.service" ];
preStart = ''
set +e
echo "Checking that bitcoind is up"
# Give bitcoind time to create pid file
sleep 2
while true
do
'${cfg.package}'/bin/bitcoin-cli -datadir='${cfg.dataDir}' getnetworkinfo > /dev/null
if [ "$?" -eq 0 ]; then
break
fi
sleep 1
script = ''
cd ${cfg.cli}/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..."
. ${./banlist.cli.txt}
'';
serviceConfig = {
User = "${cfg.user}";
Group = "${cfg.group}";
script = ''
echo "Importing node banlist..."
cd ${cfg.cli}/bin
. ${./banlist.cli.txt}
'';
# Permission for preStart
PermissionsStartOnly = "true";
} // nix-bitcoin-services.defaultHardening
// nix-bitcoin-services.allowTor;
};