onevent/startupshutdown: run command once per server block (#1934)

This commit is contained in:
elcore 2017-10-23 00:27:44 +02:00 committed by GitHub
parent e5d04f9a96
commit fc75527eb5
2 changed files with 12 additions and 6 deletions

View file

@ -20,9 +20,12 @@ func setup(c *caddy.Controller) error {
} }
// Register Event Hooks. // Register Event Hooks.
for _, cfg := range config { c.OncePerServerBlock(func() error {
caddy.RegisterEventHook("on-"+cfg.ID, cfg.Hook) for _, cfg := range config {
} caddy.RegisterEventHook("on-"+cfg.ID, cfg.Hook)
}
return nil
})
return nil return nil
} }

View file

@ -36,9 +36,12 @@ func Startup(c *caddy.Controller) error {
} }
// Register Event Hooks. // Register Event Hooks.
for _, cfg := range config { c.OncePerServerBlock(func() error {
caddy.RegisterEventHook("on-"+cfg.ID, cfg.Hook) 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'") fmt.Println("NOTICE: Startup directive will be removed in a later version. Please migrate to 'on startup'")