From fc75527eb5ea9d0252bb3079a0137dbbfb754790 Mon Sep 17 00:00:00 2001 From: elcore Date: Mon, 23 Oct 2017 00:27:44 +0200 Subject: [PATCH] onevent/startupshutdown: run command once per server block (#1934) --- onevent/on.go | 9 ++++++--- startupshutdown/startupshutdown.go | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/onevent/on.go b/onevent/on.go index 2b0d3e6af..2e291052b 100644 --- a/onevent/on.go +++ b/onevent/on.go @@ -20,9 +20,12 @@ func setup(c *caddy.Controller) error { } // Register Event Hooks. - for _, cfg := range config { - caddy.RegisterEventHook("on-"+cfg.ID, cfg.Hook) - } + c.OncePerServerBlock(func() error { + for _, cfg := range config { + caddy.RegisterEventHook("on-"+cfg.ID, cfg.Hook) + } + return nil + }) return nil } diff --git a/startupshutdown/startupshutdown.go b/startupshutdown/startupshutdown.go index cb7e7119d..72fe9225c 100644 --- a/startupshutdown/startupshutdown.go +++ b/startupshutdown/startupshutdown.go @@ -36,9 +36,12 @@ func Startup(c *caddy.Controller) error { } // Register Event Hooks. - for _, cfg := range config { - caddy.RegisterEventHook("on-"+cfg.ID, cfg.Hook) - } + c.OncePerServerBlock(func() error { + for _, cfg := range config { + caddy.RegisterEventHook("on-"+cfg.ID, cfg.Hook) + } + return nil + }) fmt.Println("NOTICE: Startup directive will be removed in a later version. Please migrate to 'on startup'")