Commit 705015c
authored
feat(connect): detect existing instance before install (disconnect + reinstall or cancel) (#76)
* feat(connect): detect existing instance before install; disconnect + reinstall or cancel
Re-running the one-liner over a live edge-connect container would collide with
the existing tunnel, container name, and host ports. The installers now detect a
container named $DZ_NAME before any host prep or docker run, warn that an
instance already exists, and prompt to reinstall or cancel. On reinstall they
print "Uninstalling existing instance...", run `doublezero disconnect` inside the
old container to drop the tunnel cleanly, then remove it. On cancel they abort
and leave the running instance untouched. Non-interactive runs (DZ_ASSUME_YES=1)
reinstall. Applied identically to all three installers.
* fix(connect): graceful, bounded teardown of an existing instance; robust headless detection
Address review of the existing-instance guard:
- Graceful, bounded teardown: replace the raw unbounded `docker exec … doublezero
disconnect` with `docker stop`, so the container entrypoint's SIGTERM trap runs
its own bounded disconnect (releasing the GRE tunnel/routes/on-chain session)
before doublezerod is killed. The stop is timeout-guarded so a wedged or
restarting container can't hang the installer forever.
- Warn loudly on orphaned state: after removal, verify the doublezero1 tunnel
interface is gone from the host netns (the container is --network host) and warn
if it lingers, and warn if the stop timed out/errored before the forced removal.
- Preserve headless automation: a no-TTY run with DZ_ASSUME_YES unset now
reinstalls (with a notice) instead of aborting, matching pre-guard behaviour;
an interactive decline still aborts, with distinct messaging.
- Robust TTY detection: probe an actual /dev/tty open rather than trusting `-r`
(a readable inode still fails to open with no controlling terminal), which also
sidesteps confirm()'s tty read in that case.
- Network-aware prompt: name the existing instance's env/image (all three
installers share DZ_NAME, so the testnet installer can find a live mainnet one).
- Add tests/scripts/reinstall_existing.bats: running (stop-before-rm ordering),
stopped (no stop), no-instance (no-op), and headless (reinstall, not abort).
* fix(connect): guard the env-label command sub against set -o pipefail abort
The existing-instance env label built its value with a bare
`docker inspect … | sed | head -1` command substitution, missing the `|| true`
its DZ_IMAGE sibling has. Under `set -euo pipefail` a failing docker inspect
(container removed between the `ps -a` detection and the inspect, or a daemon
blip) — or `head` closing the pipe early on multi-line env — makes the pipeline
non-zero and aborts the whole installer before the "already exists" warning even
prints. Add `|| true` so the label stays best-effort.
Also harden the bats stub: `docker inspect` now emits realistic multi-line env +
an image (exercising the DZ_ENV extraction and the head-closes-pipe path) and can
be told to fail via STUB_INSPECT_FAIL. New test asserts a mid-teardown inspect
failure still detects, warns, and reinstalls; the running-instance test now
asserts the warning names the victim's env/image.1 parent 3ccf056 commit 705015c
5 files changed
Lines changed: 382 additions & 0 deletions
File tree
- scripts
- tests/scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
293 | 311 | | |
294 | 312 | | |
295 | 313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
365 | 431 | | |
366 | 432 | | |
367 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
357 | 357 | | |
358 | 358 | | |
359 | 359 | | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
360 | 426 | | |
361 | 427 | | |
362 | 428 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
357 | 357 | | |
358 | 358 | | |
359 | 359 | | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
360 | 426 | | |
361 | 427 | | |
362 | 428 | | |
| |||
0 commit comments