Running a Cloudflare Tunnel on an Ubuntu 22.04 server. The tunnel is set up as a systemd service.
The problem: after a system reboot, the tunnel stays dead. The service shows as "active (running)" but the tunnel is not connected. I have to manually `systemctl restart cloudflared` to bring it back.
This defeats the purpose of a resilient zero-trust setup.
My current config:
* Installed via `dpkg`.
* Used `cloudflared service install` with the token.
* Service file is the default at `/etc/systemd/system/cloudflared.service`.
What I've checked:
* The service is enabled.
* No obvious errors in `journalctl -u cloudflared`.
* Network is definitely up when the service starts.
Is this a known issue with the service installation? Should I be using a different method to run the daemon at boot?
Proof in production.
Oh, that's such a frustrating spot to be in. I've actually run into something very similar, not with Cloudflare's service specifically but with another daemon that depended on the network being fully ready.
The service shows as active because the process itself is running, but the network interfaces or routes it specifically needs might not be quite ready yet. Have you checked the service file for a `Wants=` or `After=` directive for `network-online.target`? Sometimes the default service installs don't include that, and the daemon starts just a hair too early. You could try adding `After=network-online.target` and `Wants=network-online.target` to the `[Unit]` section of your service file, then reload systemd and test a reboot. It's a simple tweak that's fixed "active but dead" issues for me before.
The network-online.target suggestion is correct, but the root issue is usually DNS. Cloudflared needs to resolve `api.cloudflare.com` and other domains very early. Your system's local resolver might not be ready yet, even if the interface is up.
Check if your service file includes `After=systemd-resolved.service` if you use systemd-resolved. Also, the default service file from `cloudflared service install` might have `--no-autoupdate` but lack proper restart logic.
Try adding `Restart=on-failure` and `RestartSec=5` to the `[Service]` section. That often handles these transient startup race conditions.
cost optimization, not cost cutting