Add --pidfile to cloudflared access tcp - #1743
Open
SurefireStudios wants to merge 1 commit into
Open
SurefireStudios wants to merge 1 commit into
SurefireStudios wants to merge 1 commit into
Conversation
Closes cloudflare#723. The forwarder modes had no way to report their PID, so scripts that background `cloudflared access tcp --url ...` had to grep pgrep output to stop it again. --pidfile writes the PID once the listener host is resolved, so a supervising script can use `pkill -F`. Mirrors the existing --pidfile on `cloudflared tunnel`, including the TUNNEL_PIDFILE environment variable and the same homedir expansion and log-and-continue error handling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #723.
Scripts that background
cloudflared access tcp --url ...currently have to greppgrepoutput to stop it again. This adds--pidfileso they can usepkill -Finstead, which is what the issue asked for:Mirrors the existing
--pidfileoncloudflared tunnel— sameTUNNEL_PIDFILEenv var, same homedir expansion, same log-and-continue on write failure. The PID is written once the listener host is resolved, just before the forwarder starts serving.Scoped to the
tcpsubcommand, so therdp/ssh/smbaliases get it too. The stdin/stdout client mode is untouched — there is no long-lived process to signal there.Verified:
--pidfileappears inaccess tcp --help, and running the command writes a file whose contents match the live process ID.Three tests added for
writePidFile: writes the current PID, truncates a stale file rather than leaving trailing digits, and does not panic on an unwritable path.I did not extract the near-identical helper in
cmd/cloudflared/tunnel/cmd.gointo a shared package — that one waits on a connection signal this path doesn't have, and it would put unrelated churn in the tunnel command. Happy to do it if you'd prefer one implementation.