Skip to content

fix: Keep the service token file when a Linux service install fails - #1806

Open
0xABCD01 wants to merge 1 commit into
cloudflare:masterfrom
0xABCD01:fix/1774-keep-token-on-install-failure
Open

0xABCD01 wants to merge 1 commit into
cloudflare:masterfrom
0xABCD01:fix/1774-keep-token-on-install-failure

Conversation

@0xABCD01

Copy link
Copy Markdown

Fixes #1774.

cloudflared service install <token> on Linux deleted the token file whenever any later install step failed. When the service definition had already been generated (or was present from an earlier install), the enabled unit kept pointing at the missing token file and restarted in a loop, and re-running the install failed again at generating the definition, so the state could not be recovered by retrying.

This removes the failure cleanup. The token file stays in place when an install fails, and service uninstall remains the path that removes it; it already calls removeTokenFile unconditionally. To make the behaviour testable, the install flow is split into installLinuxServiceWith, which takes the config directory and the init-specific install step as parameters. The init dispatch itself is unchanged, moved into installLinuxServiceForInit.

Tests:

  • TestInstallLinuxServiceWithToken: an install failing at service-definition generation, an install failing at service start, and a successful install. The token file survives all three.
  • TestRemoveTokenFile: uninstall still removes the token file, and removing a missing file is not an error.
  • The full cmd/cloudflared package test suite passes, as do go vet and gofmt on the changed files.

Disclosure: PR #1787 attempted the same fix in a larger form and was closed by its author without maintainer review. This PR is a smaller take on the same change.

Note: the same failure-cleanup pattern exists in the macOS and Windows service installers. This PR only changes Linux, which is what #1774 reports.

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.

🐛 Cannot use service install

1 participant