bitcoind: wait until RPC port is open
This fixes rare failures in clightning which requires an open bitcoind RPC port
This commit is contained in:
parent
5536b64fb3
commit
ad7a519284
@ -19,7 +19,7 @@ let
|
|||||||
listen=${if cfg.listen then "1" else "0"}
|
listen=${if cfg.listen then "1" else "0"}
|
||||||
|
|
||||||
# RPC server options
|
# RPC server options
|
||||||
${optionalString (cfg.rpc.port != null) "rpcport=${toString cfg.rpc.port}"}
|
rpcport=${toString cfg.rpc.port}
|
||||||
${concatMapStringsSep "\n"
|
${concatMapStringsSep "\n"
|
||||||
(rpcUser: "rpcauth=${rpcUser.name}:${rpcUser.passwordHMAC}")
|
(rpcUser: "rpcauth=${rpcUser.name}:${rpcUser.passwordHMAC}")
|
||||||
(attrValues cfg.rpc.users)
|
(attrValues cfg.rpc.users)
|
||||||
@ -108,9 +108,9 @@ in {
|
|||||||
|
|
||||||
rpc = {
|
rpc = {
|
||||||
port = mkOption {
|
port = mkOption {
|
||||||
type = types.nullOr types.ints.u16;
|
type = types.ints.u16;
|
||||||
default = null;
|
default = 8332;
|
||||||
description = "Override the default port on which to listen for JSON-RPC connections.";
|
description = "Port on which to listen for JSON-RPC connections.";
|
||||||
};
|
};
|
||||||
users = mkOption {
|
users = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
@ -241,6 +241,12 @@ in {
|
|||||||
echo "rpcpassword=$(cat /secrets/bitcoin-rpcpassword)" >> '${cfg.dataDir}/bitcoin.conf'
|
echo "rpcpassword=$(cat /secrets/bitcoin-rpcpassword)" >> '${cfg.dataDir}/bitcoin.conf'
|
||||||
chmod -R g+rX '${cfg.dataDir}/blocks'
|
chmod -R g+rX '${cfg.dataDir}/blocks'
|
||||||
'';
|
'';
|
||||||
|
# Wait until RPC port is open. This usually takes just a few ms.
|
||||||
|
postStart = ''
|
||||||
|
while ! { exec 3>/dev/tcp/127.0.0.1/${toString cfg.rpc.port}; } &>/dev/null; do
|
||||||
|
sleep 0.05
|
||||||
|
done
|
||||||
|
'';
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
User = "${cfg.user}";
|
User = "${cfg.user}";
|
||||||
|
Loading…
Reference in New Issue
Block a user