A self-healing, native-compiled Java toolchain that automates the deployment of persistent Cloudflare Tunnels and reverse-proxying Cloudflare Workers for multiple local services. It provides a seamless, non-interactive setup experience by automatically fetching your Cloudflare Account ID using an API Token and ensures the software runs as an efficient native binary with minimal configuration requirements.
The project consists of two binaries compiled as native executables (using GraalVM):
setup-cli-native: A CLI tool to configure the initial setup, Cloudflare API tokens, and local service mappings.tunnel-daemon-native: A long-running daemon that spawns and monitorscloudflaredtunnels and automatically updates the Cloudflare Worker when tunnels change or reconnect.
To build the native binaries, you will need Maven and GraalVM with native-image capabilities installed:
mvn clean package -PnativeThe resulting executables will be available in the target/ directory:
target/setup-cli-nativetarget/tunnel-daemon-native
For a persistent and standardized setup on Linux, it is highly recommended to move the binaries to /usr/local/bin and store configuration in /opt/cf-p-link. This ensures the daemon is not accidentally deleted during development or cleanup.
-
Copy Binaries to standard execution path:
sudo cp target/setup-cli-native /usr/local/bin/ sudo cp target/tunnel-daemon-native /usr/local/bin/
-
Create the configuration directory:
sudo mkdir -p /opt/cf-p-link
-
Run the setup CLI tool from the configuration directory:
cd /opt/cf-p-link sudo setup-cli-nativeFollow the interactive prompts to provide your Cloudflare API Token. Once configured, a
config.jsonfile will be created in/opt/cf-p-link. -
Install and enable the Systemd service: A
cf-p-link.servicefile is provided in the repository root (already configured to use/usr/local/binand/opt/cf-p-link).sudo cp cf-p-link.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable --now cf-p-link.service -
Check the status and logs:
sudo systemctl status cf-p-link.service sudo journalctl -u cf-p-link.service -f
If you prefer testing before installing as a service, you can run the binaries directly from your project folder:
- Configure your services first:
./target/setup-cli-native
- Start the daemon directly:
./target/tunnel-daemon-native
The config.json file stores all necessary information. If you ever need to change the Cloudflare API Token, Account ID, or service mappings, you can manually edit config.json (located at /opt/cf-p-link/config.json if installed system-wide) or re-run the setup-cli-native tool in that directory.
If you need to completely remove cf-p-link from your system, run the following commands:
-
Stop and disable the systemd service:
sudo systemctl disable --now cf-p-link.service
-
Remove the systemd service file:
sudo rm /etc/systemd/system/cf-p-link.service sudo systemctl daemon-reload sudo systemctl reset-failed
-
Remove the installed binaries:
sudo rm /usr/local/bin/setup-cli-native sudo rm /usr/local/bin/tunnel-daemon-native
-
Remove the configuration directory (this deletes all setup data and API tokens):
sudo rm -rf /opt/cf-p-link