The issue where GL.iNet router users find that Cloudflare Tunnel does not run after rebooting the device (successfully tested on OpenWrt 25.12). So I created a script to solve this problem. The device I tested was the MT6000.
To use a Cloudflare Tunnel, first install the cloudflared plugin from the app store, then enter the domain and token information to successfully connect to the tunnel.
The restart script uses hotplug.d to monitor ifup and resolve the race condition caused by the network not being ready during startup; it rewrites status() to prevent inconsistencies between the ubus status and the LuCI display; and works with procd's native daemon management to provide silent recovery with low overhead.
The script is as follows:
Step 1: Rewrite the service script and clean up residual processes. “Replace Your_Token_Here with the actual token.”
cat << 'EOF' > /etc/init.d/cloudflared
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=95
STOP=10
TUNNEL_TOKEN="Your_Token_Here"
start_service() {
procd_open_instance cloudflared
procd_set_param command /usr/bin/cloudflared tunnel --no-autoupdate run --token "$TUNNEL_TOKEN"
procd_set_param respawn 3600 5 0
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
status() {
if pidof cloudflared >/dev/null 2>&1; then
echo "running"
return 0
else
echo "inactive"
return 1
fi
}
EOF
chmod +x /etc/init.d/cloudflared
killall -9 cloudflared 2>/dev/null
/etc/init.d/cloudflared restart
Step 2: Create an automatic network-connectivity trigger script (Hotplug)
mkdir -p /etc/hotplug.d/iface
cat << 'EOF' > /etc/hotplug.d/iface/99-cloudflared
#!/bin/sh
# As soon as an external network interface is connected (ifup), immediately start/restart cloudflared
if [ "$ACTION" = "ifup" ]; then
/etc/init.d/cloudflared restart
fi
EOF
chmod +x /etc/hotplug.d/iface/99-cloudflared
Step 3: Start the service
/etc/init.d/cloudflared start