From 97710ced7ea5b5d8025dc6a3e43d82e9a280920e Mon Sep 17 00:00:00 2001 From: Kevin Stock Date: Sun, 1 Oct 2017 19:36:23 -0700 Subject: [PATCH] Add hook for instance startup (#1888) Provides a new hook for plugins as a means to provide the current caddy.Instance when starting or restarting. --- caddy.go | 3 +++ caddy/caddymain/run.go | 3 +++ plugins.go | 7 ++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/caddy.go b/caddy.go index 3225917b..902a1a39 100644 --- a/caddy.go +++ b/caddy.go @@ -213,6 +213,9 @@ func (i *Instance) Restart(newCaddyfile Input) (*Instance, error) { } i.Stop() + // Execute instantiation events + EmitEvent(InstanceStartupEvent, newInst) + log.Println("[INFO] Reloading complete") return newInst, nil diff --git a/caddy/caddymain/run.go b/caddy/caddymain/run.go index 106b6e5e..81f97f2a 100644 --- a/caddy/caddymain/run.go +++ b/caddy/caddymain/run.go @@ -140,6 +140,9 @@ func Run() { mustLogFatalf("%v", err) } + // Execute instantiation events + caddy.EmitEvent(caddy.InstanceStartupEvent, instance) + // Twiddle your thumbs instance.Wait() } diff --git a/plugins.go b/plugins.go index 8fbc4ec9..f5372184 100644 --- a/plugins.go +++ b/plugins.go @@ -233,9 +233,10 @@ type EventName string // Define names for the various events const ( - StartupEvent EventName = "startup" - ShutdownEvent EventName = "shutdown" - CertRenewEvent EventName = "certrenew" + StartupEvent EventName = "startup" + ShutdownEvent EventName = "shutdown" + CertRenewEvent EventName = "certrenew" + InstanceStartupEvent EventName = "instancestartup" ) // EventHook is a type which holds information about a startup hook plugin.