Skip to content

feat: add --pidfile support for access subcommand#1623

Open
juliosuas wants to merge 1 commit intocloudflare:masterfrom
juliosuas:feat/access-pidfile
Open

feat: add --pidfile support for access subcommand#1623
juliosuas wants to merge 1 commit intocloudflare:masterfrom
juliosuas:feat/access-pidfile

Conversation

@juliosuas
Copy link
Copy Markdown

Summary

Add --pidfile support to the cloudflared access tcp (and its aliases ssh, rdp, smb) subcommand.

Closes #723

Problem

The --pidfile flag works for cloudflared tunnel but not for cloudflared access subcommands. Users running cloudflared access tcp as a daemon need pidfile support for process management with systemd, launchd, or custom init scripts.

Solution

  • Register the --pidfile flag on the access tcp subcommand (also exposed via TUNNEL_PIDFILE env var, matching the tunnel command)
  • Write the PID file immediately on startup
  • Clean up (remove) the PID file on exit via defer
  • Reuse the same go-homedir path expansion already used by the tunnel pidfile implementation

The implementation is intentionally minimal — it follows the same pattern as the existing tunnel --pidfile support.

Usage

# Start an access TCP forwarder with pidfile
cloudflared access tcp --hostname example.com --url localhost:2222 --pidfile /var/run/cloudflared-access.pid

# Works with systemd for daemon management
# PIDFile=/var/run/cloudflared-access.pid in your .service unit

# Also works via environment variable
TUNNEL_PIDFILE=/var/run/cloudflared-access.pid cloudflared access ssh --hostname example.com

Changes

  • cmd/cloudflared/access/cmd.go — added pidfile flag constant and registered the flag on the tcp subcommand
  • cmd/cloudflared/access/carrier.go — added pidfile write on startup with deferred cleanup on exit

Add --pidfile flag to the 'access tcp' (ssh/rdp/smb) subcommand, matching
the existing behavior of 'cloudflared tunnel --pidfile'.

When set, the process writes its PID to the specified file on startup and
removes it on exit, enabling daemon management with systemd, launchd, or
custom init scripts.

Closes cloudflare#723
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"

1 participant