It starts listening to :8087 before php-fpm is ready and google cloud run doesn’t have it’s own readiness checks and so it’s possible to get these errors because Google Cloud run thinks that my web server exists.
I already have the lb_try_duration but it seems that sometimes isn’t long enough and I’d rather not make it much larger than it is.
If I instead make it so the Caddyfile uses :8086 and then I use the admin endpoint to change it to :8087 when php-fpm is up and running, then php-fpm gets restarted cause I’m using the supervise module to run php-fpm so that I don’t have to manage separately to caddy in the docker container.
Is it possible to have readiness checks so that it doesn’t start listening to :8087 until the fpm.sock file exists?
I think it would make more sense for supervisor to have health checks for services it runs and optionally block Caddy’s startup from completing until ready, or something like that.
I had another idea but it won’t work (because php_fastcgi expects the upstream to speak fastcgi but Caddy doesn’t have a fastcgi server you could use for this). The idea is that you could run a 2nd server in Caddy and make it a secondary upstream, and as long as the primary is unhealthy, it would get hit. Active health checks would be necessary for this to work.
# Main
:8087 {
php_fastcgi unix/../../runtime/fpm.sock localhost:8888 {
lb_policy first
health_uri /health
health_interval 2s
health_timeout 250ms
}
}
# Imagine this is a fastcgi server (not http)
:8888 {
php_fastcgi unix/../../runtime/fpm.sock {
lb_try_duration 60s
}
}
The lb policy would make requests to the first upstream get skipped until health checks say the first upstream is ok, but the fallback server would have a pretty long try duration so the original requests would still work (maybe).
Another idea; we could potentially add a placeholder like {config.seconds_since_startup} (name TBD) which could be used with the expression matcher to have different routing behaviour in say the first minute or so of the config running:
Seems if I start and stop using Provisioner and CleanerUpper instead of Start() and Stop() I can prevent caddy from creating the :8087 socket before php is ready
I didn’t take a deep look at the code, but I like this; would make for a good off-the-shelf way to run Caddy + PHP-FPM in a single container for pretty much anyone.
One thing I noticed – by convention, directives/app names should use underscores, not dashes, so it should be php_fpm, for consistency.
Also, I think it would be nice to include a sample Dockerfile in that github repo as well, for those who might want a quick place to get started with it (example of using caddy:builder + installing php-fpm etc)