Possible startup for Caddyfile, not virtual host

Hello there,

I have multiple virtual hosts in my Caddyfile and if I write in every block to start php-fpm on startup and stop it on shutdown, it’s also started multiple times etc.
Is there a way to have a startup script for the Caddyfile and not for every single virtual host?
I want to start php-fpm only once.
Maybe it’s possible but I’m to stupid? :sweat:

Have a nice day,

The startup and shutdown directives run once for each appearance in the Caddyfile. (I could probably clarify this in the docs, which I see is currently a little confusing about this.) So just put it in for one site instead.

Thanks for the answer.
Are there any plans to implement these global directives? Do you say strictly no or can I open a feature request on github?

I don’t think that’s something we want to do, because the Caddyfile is supposed to be simple; see issue https://github.com/mholt/caddy/issues/619 for a lengthy discussion on the matter of shared or global directives.

1 Like

I agree it’s a bit silly. I have to remember to startup in a vhost definition which I’m unlikely to remove currently.

Maybe the solution is to not boot the process with Caddy and use systemd or docker compose. However those approaches require far more complex setups. Bleh.

@matt I have read through #619 and while I understand the sentiments put forward in that issue around not wanting to make the caddyfile complicated or computed, you could argue that startup and shutdown are special cases.

Many sites will use Caddy and php-fastcgi to server their sites and this requires 1 fastcgi endpoint to be started for potentially many virtualhosts. Simply allowing startup to be placed outside a block as import currently is would allow for very obvious logic

 startup myscript.bat &
 shutdown myendscript.bat &
 example.com {
     root c:\websites\example.com

 another.example.com {
    startup AnotherSpecificScript.bat &
    root d:\web\another

I think this is obvious what is going on an doesnto add additional complexity (unless I’m missing something)

In the meantime @hendry can you do something like this

 localhost:7766 {
    startup c:\scriptyouneedtorun.bat &
    shutdown c:\shutdownscript.bat &
    root c:\dummyroot

I don’t want to create more special cases. Import is too many as it is. Besides, it doesn’t make sense for a web server to become a process manger too.

That’s not obvious. Now you can’t have a site at hostname of startup for example.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.