Skip to content

Add --pidfile support with signal-aware cleanup to cloudflared access…#1599

Open
Enginerd-2019 wants to merge 1 commit intocloudflare:masterfrom
Enginerd-2019:pidfile-access-support
Open

Add --pidfile support with signal-aware cleanup to cloudflared access…#1599
Enginerd-2019 wants to merge 1 commit intocloudflare:masterfrom
Enginerd-2019:pidfile-access-support

Conversation

@Enginerd-2019
Copy link

Summary

Adds --pidfile flag to cloudflared access tcp (and its aliases: rdp, ssh, smb).

  • Writes the process PID to the specified file after startup
  • Cleans up the PID file on exit — handles both graceful shutdown (defer) and signals (SIGTERM/SIGINT)
  • Follows the same pattern as the tunnel command's existing --pidfile support
  • Includes unit tests for both writePidFile and removePidFile

Closes #723

How it differs from #1579

This PR improves on the existing attempt (#1579) with:

  1. Signal-aware PID file cleanup — traps SIGTERM/SIGINT to remove the file before exiting, preventing stale PIDs when using kill <pid>
  2. Graceful shutdown cleanupdefer removePidFile() covers error exits and normal shutdowns
  3. Unit tests — new carrier_test.go with tests for write, cleanup, and error handling

Test plan

  • make fmt-check passes
  • make lint passes
  • make test passes (including new unit tests)
  • ./cloudflared access tcp --help shows the --pidfile flag
  • Manual test: PID file is written on startup and cleaned up on kill

… tcp

Add --pidfile flag to the access tcp subcommand (also applies to rdp,
ssh, and smb aliases). This writes the process ID to a file after
startup and removes it on exit.

Signal handling (SIGTERM/SIGINT) ensures the PID file is cleaned up
when the process is killed, not just on graceful shutdown.

Includes unit tests for writePidFile and removePidFile.

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