Skip to content

Warn when borgmatic is run directly instead of via borgmatic-start#240

Merged
modem7 merged 5 commits into
masterfrom
feat/borgmatic-direct-warning
Jun 27, 2026
Merged

Warn when borgmatic is run directly instead of via borgmatic-start#240
modem7 merged 5 commits into
masterfrom
feat/borgmatic-direct-warning

Conversation

@modem7

@modem7 modem7 commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Summary

borgmatic-start traps SIGTERM/INT/HUP and forwards them to the borgmatic process, so a docker stop during a backup is handled gracefully. Running borgmatic directly via docker exec bypasses this entirely with no indication to the user.

This PR adds a runtime warning when borgmatic is invoked outside of borgmatic-start:

WARNING: borgmatic is running directly, not via borgmatic-start. Signal handling (SIGTERM/INT/HUP) will not be forwarded to borgmatic.

The warning is suppressed automatically when called via borgmatic-start (which sets BORGMATIC_VIA_START=1).

Implementation:

  • Dockerfile: rename pip-installed borgmaticborgmatic.bin after install
  • root/usr/local/bin/borgmatic: wrapper that checks BORGMATIC_VIA_START and warns if unset, then execs borgmatic.bin
  • root/usr/local/bin/borgmatic-start: prefix the borgmatic call with BORGMATIC_VIA_START=1

Test plan

  • CI build passes
  • docker exec Borgmatic borgmatic --version prints the warning
  • docker exec Borgmatic borgmatic-start --version does not print the warning
  • Scheduled cron runs (via borgmatic-start) do not print the warning

modem7 and others added 5 commits June 27, 2026 13:11
borgmatic-start traps SIGTERM/INT/HUP and forwards signals to the
borgmatic process. Running borgmatic directly (e.g. docker exec) bypasses
this, meaning a container stop during a backup won't be handled gracefully.

Implementation:
- Rename the pip-installed borgmatic binary to borgmatic.bin
- Add a wrapper at borgmatic that checks for BORGMATIC_VIA_START env var
  and prints a warning if absent, then exec's borgmatic.bin
- Set BORGMATIC_VIA_START=1 in borgmatic-start to suppress the warning

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
DL3013: pip install -U pip is intentionally unpinned (always want latest pip)
DL3018: borgmatic-bash-completion unpinned (tracks borgmatic version from Alpine)
DL3042: --no-cache-dir omitted intentionally — using BuildKit cache mount instead

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
with-contenv reads /run/s6/container_environment which doesn't exist
when borgmatic is run directly (--entrypoint or docker exec before s6
init). The wrapper is a thin passthrough and doesn't need the s6
container environment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The borgmatic wrapper now prints a WARNING containing 'borgmatic' before
s6 init completes. The CI test was polling for 'borgmatic' in logs as a
readiness signal, which fired immediately on the warning — before
svc-cron/run had printed the version table.

'Time Zone:' only appears at the end of the version table, making it a
reliable sentinel that the container is fully initialised.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…check

borgmatic --version at startup hits the wrapper which emits the
BORGMATIC_VIA_START warning, since s6 init is not a backup run.
Use borgmatic.bin directly for the version display — the wrapper
warning is only meaningful for actual backup invocations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@modem7 modem7 merged commit 54e95b5 into master Jun 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant