Dynamically Load Caddy File

At the bottom of https://github.com/mholt/caddy/wiki/Writing-a-Plugin:-Caddyfile-Loader there’s mention of “Dynamic Reloads”. I’d like to know how to go about doing this. I’m willing to update the wiki when I figure it out too.

Thanks!

I’ve got this working by sending a USR1 to myself, but it feels like such a hack:

go func() {
    self, _ := os.FindProcess(os.Getpid())
    for {
        time.Sleep(2 * time.Second)
        self.Signal(syscall.SIGUSR1)
    }
}()

Yeah, there’ll be a programmatic way to do this; it’s not yet implemented (I didn’t get it into the 0.9 release as I hoped) but as I start working on the API I think this will eventually roll out!

Ah, that’s what the “TODO” means then :slight_smile: Thanks!

The capability is there (caddy.Instance.Restart(newCaddyfile)) but as of right now there is not a way to access the instance from the plugin.

Hi guys any update on dynamic reloads? We are looking at a way to modify the caddyfile from a db, redis, or file. Thanks!

From within a Caddy plugin? (That’s what we’re talking about here.)

Any update on reloading from a plugin? (I’m working on a plugin that dynamically generates the caddyfile configuration from Kubernetes)

Not yet, as in, we haven’t implemented this. It’s just a matter of calling Restart() on the instance. The plugin needs access to the Instance.

@matt would you be open to a new interface simulator to caddy.AfterStartup that plugins could register for and would provide the instance after startup?

An interface simulator?

simular to…shouldn’t be responding from a mobile keyboard

2 Likes

Ah… That makes more sense. :slight_smile: Yes, that’s quite possible! I’d be willing to review such a change, anyway.

Pull request 1888 has been approved which provide the ability for plugins to be notified via the hook mechanism when instances are started as a means to access the instance from a plugin (once merged). The pull request includes a code sample as well: :tada:

https://github.com/mholt/caddy/pull/1888

1 Like