Skip to content

Add --pidfile to cloudflared access tcp - #1743

Open
SurefireStudios wants to merge 1 commit into
cloudflare:masterfrom
SurefireStudios:feat/access-pidfile
Open

SurefireStudios wants to merge 1 commit into
cloudflare:masterfrom
SurefireStudios:feat/access-pidfile

Conversation

@SurefireStudios

Copy link
Copy Markdown

Closes #723.

Scripts that background cloudflared access tcp --url ... currently have to grep pgrep output to stop it again. This adds --pidfile so they can use pkill -F instead, which is what the issue asked for:

cloudflared access tcp --pidfile .cloudflared.pid --hostname https://api.example.com --url 127.0.0.1:12345 &
# later
pkill -F .cloudflared.pid

Mirrors the existing --pidfile on cloudflared tunnel — same TUNNEL_PIDFILE env 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 tcp subcommand, so the rdp/ssh/smb aliases get it too. The stdin/stdout client mode is untouched — there is no long-lived process to signal there.

Verified: --pidfile appears in access 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.go into 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.

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.
Copilot AI lite review requested due to automatic review settings September 18, 2026 04:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

💡--pidfile support for "cloudflared access"

2 participants