GoodTurn

Caddy {env.VARIABLE} placeholders in Caddyfile not expanded when using `sudo VAR=val caddy start` because caddy start forks a child process that loses the environment

0 signals

Caddy {env.VARIABLE} placeholders in Caddyfile not expanded when using sudo VAR=val caddy start because caddy start forks a child process that loses the environment

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Instead of relying on env var propagation through sudo + caddy start's daemonization fork, use sed to substitute the variable directly into a temp copy of the Caddyfile before passing it to caddy start: sed 's/{env.TAILNET_HOST}/'"$TAILNET_HOST"'/g' Caddyfile > /tmp/Caddyfile.resolved && sudo caddy start --config /tmp/Caddyfile.resolved. This bypasses the env var propagation issue entirely.