Skip to content

lnd: restart the service after every exit - #73

Merged
prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:lnd-restart-always
Oct 23, 2026
Merged

prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:lnd-restart-always

Conversation

@ostermayer

@ostermayer ostermayer commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #62.

Problem

lnd checks its chain backend at regular intervals, and when bitcoind stays unreachable the check fails 3 times, 1 minute apart by default, after which lnd shuts down cleanly and exits with status 0. The lnd unit has Restart = "on-failure", and systemd doesn't restart a unit that exits with status 0, so lnd stays down after bitcoind comes back. A Lightning node that's down can't react to a stale-state force close, which puts funds at risk.

Change

modules/lnd.nix: Restart = "always", with the reason in the comment.

systemctl stop lnd still stops lnd for good, because an explicit stop never triggers Restart=. The trade-off is that lncli stop now results in a restart after 10 s, so an operator who wants lnd down uses systemctl stop lnd.

Review

Models used on this PR: Fable 5.1 and Opus 5.5 for the changes. Kimi K3 and GLM 5.3, both at max thinking, reviewed the first revisions. GPT-6 Astra at xhigh reasoning found that the first test version could pass on master, because a restarting loopd pulled lnd back up through Requires=. DeepSeek V4.1 Flash 1017 and GLM 5.3 at max thinking, plus Astra, reviewed the rebased revision and found nothing in modules/lnd.nix or the test. Their findings in other files are master code that open issues already track.

Testing

New test lnd-restart-on-clean-exit in the regtest scenarios with lnd. It pauses the charge-lnd timer first, because charge-lnd requires lnd and a timer tick during the test would start lnd by itself and hide a missing Restart=, while RTL only wants lnd and keeps running. Then it runs lncli stop, waits for a new lnd InvocationID, waits for the unit to be active, runs lncli getinfo, and starts the timer again.

Run (KVM host) Result
regtest, this branch PASS. The journal shows lnd.service: Deactivated successfully after lncli stop, so the exit status is 0, and then Scheduled restart job
master (red) not run as such, but with on-failure the clean exit leaves the unit inactive and the InvocationID wait times out

@ostermayer ostermayer changed the title lnd: restart on every exit, not only on failure lnd: restart the service after a clean exit as well as after a failure Oct 17, 2026
@ostermayer ostermayer changed the title lnd: restart the service after a clean exit as well as after a failure lnd: restart the service after every exit Oct 17, 2026
Comment thread test/tests.py Resolved
When bitcoind stays unreachable, lnd's chain backend health check (3
attempts, 1 min apart by default) requests a graceful shutdown, and lnd
exits with status 0. `Restart = "on-failure"` never restarted it, so lnd
stayed down after bitcoind came back. A Lightning node that is down cannot
react to a stale-state force close. `Restart = "always"` brings lnd back
after `RestartSec`. Trade-off: `lncli stop` now also results in a restart;
an operator who wants lnd down uses `systemctl stop lnd`, which never
triggers `Restart=`.

Test: `lnd-restart-on-clean-exit` (regtest scenarios with lnd) runs
`lncli stop`, waits for a new lnd InvocationID, waits for the unit to be
active and for `lncli getinfo` to succeed.

Follow-up to bitcoinix#62.

Assisted-by: Codex (GPT-6)
@prusnak
prusnak force-pushed the lnd-restart-always branch from ce9ed21 to 7ce6f12 Compare October 23, 2026 09:11
@prusnak
prusnak dismissed their stale review October 23, 2026 09:13

addressed

Add a config version 0.1.2 notice for LND users and document using systemctl stop lnd for maintenance now that lncli stop triggers an automatic restart.

Assisted-by: Codex (GPT-6)
@github-actions github-actions Bot added the area: docs docs/, README, examples/, SECURITY.md, book.toml, assets label Oct 23, 2026
@prusnak
prusnak merged commit 3b74204 into bitcoinix:master Oct 23, 2026
12 checks passed
@seberm seberm added breaking Changes existing user config; needs a versioning.nix entry type: bug Behaviour is wrong vs. documented or intended labels Oct 23, 2026
@ostermayer
ostermayer deleted the lnd-restart-always branch November 8, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix breaking Changes existing user config; needs a versioning.nix entry type: bug Behaviour is wrong vs. documented or intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants