Merge fort-nix/nix-bitcoin#780: clightning: set service as active only after clnrest has started
ce6244cc69clightning: set service as active only after clnrest has started (Erik Arvstedt) Pull request description: ACKs for top commit: jonasnick: ACKce6244cc69Tree-SHA512: e92df9fc5f42ad59eb05421e1645012fc98a8bd020215fa894d22bdde8b2860b6462c1db96b4c957e256beac9b93b76336bad9eb313c0b5cc727fffbf6b42970
This commit is contained in:
commit
52809afbf4
1 changed files with 18 additions and 6 deletions
|
|
@ -54,6 +54,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
cfg = config.services.clightning.plugins.clnrest;
|
cfg = config.services.clightning.plugins.clnrest;
|
||||||
|
nbLib = config.nix-bitcoin.lib;
|
||||||
inherit (config.services) clightning;
|
inherit (config.services) clightning;
|
||||||
|
|
||||||
runePath = "${clightning.networkDir}/admin-rune";
|
runePath = "${clightning.networkDir}/admin-rune";
|
||||||
|
|
@ -68,11 +69,22 @@ in
|
||||||
clnrest-port=${toString cfg.port}
|
clnrest-port=${toString cfg.port}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
systemd.services.clightning.postStart = mkIf cfg.createAdminRune (mkAfter ''
|
systemd.services.clightning.postStart = mkAfter (
|
||||||
|
optionalString cfg.createAdminRune ''
|
||||||
if [[ ! -e '${runePath}' ]]; then
|
if [[ ! -e '${runePath}' ]]; then
|
||||||
rune=$(${clightning.cli}/bin/lightning-cli createrune | ${pkgs.jq}/bin/jq -r .rune)
|
rune=$(${clightning.cli}/bin/lightning-cli createrune | ${pkgs.jq}/bin/jq -r .rune)
|
||||||
install -m 640 <(echo "$rune") '${runePath}'
|
install -m 640 <(echo "$rune") '${runePath}'
|
||||||
fi
|
fi
|
||||||
'');
|
'' +
|
||||||
|
# Wait until the clnrest server is listening.
|
||||||
|
# Usually, the server is already listening at this point.
|
||||||
|
# But when clnrest is running for the first time, certificates are generated
|
||||||
|
# before the server starts, which can take a few seconds.
|
||||||
|
''
|
||||||
|
while ! { exec 3>/dev/tcp/${nbLib.address cfg.address}/${toString cfg.port}; } &>/dev/null; do
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
''
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue