caddy: move EmitEvent(InstanceStartupEvent, instance) (#2161)

* caddy: move EmitEvent(InstanceStartupEvent, instance)

* caddy: update SupportedEvents
This commit is contained in:
elcore 2019-01-18 18:46:21 +01:00 committed by Matt Holt
parent f3a4f46d78
commit 771dcf3d40
4 changed files with 10 additions and 7 deletions

View file

@ -498,6 +498,10 @@ func Start(cdyfile Input) (*Instance, error) {
if pidErr := writePidFile(); pidErr != nil {
log.Printf("[ERROR] Could not write pidfile: %v", pidErr)
}
// Execute instantiation events
EmitEvent(InstanceStartupEvent, inst)
return inst, nil
}

View file

@ -160,9 +160,6 @@ func Run() {
mustLogFatalf("%v", err)
}
// Execute instantiation events
caddy.EmitEvent(caddy.InstanceStartupEvent, instance)
// Begin telemetry (these are no-ops if telemetry disabled)
telemetry.Set("caddy_version", appVersion)
telemetry.Set("num_listeners", len(instance.Servers()))

View file

@ -14,7 +14,8 @@ type Config struct {
// SupportedEvents is a map of supported events.
var SupportedEvents = map[string]caddy.EventName{
"startup": caddy.InstanceStartupEvent,
"shutdown": caddy.ShutdownEvent,
"certrenew": caddy.CertRenewEvent,
"startup": caddy.StartupEvent,
"instance_startup": caddy.InstanceStartupEvent,
"shutdown": caddy.ShutdownEvent,
"certrenew": caddy.CertRenewEvent,
}

View file

@ -45,7 +45,8 @@ func TestCommandParse(t *testing.T) {
}{
{name: "noInput", input: `on`, shouldErr: true},
{name: "nonExistent", input: "on xyz cmd arg", shouldErr: true},
{name: "startup", input: `on startup cmd arg1 arg2`, shouldErr: false, config: hook.Config{Event: caddy.InstanceStartupEvent, Command: "cmd", Args: []string{"arg1", "arg2"}}},
{name: "startup", input: `on startup cmd arg1 arg2`, shouldErr: false, config: hook.Config{Event: caddy.StartupEvent, Command: "cmd", Args: []string{"arg1", "arg2"}}},
{name: "instance_startup", input: `on instance_startup cmd arg1 arg2`, shouldErr: false, config: hook.Config{Event: caddy.InstanceStartupEvent, Command: "cmd", Args: []string{"arg1", "arg2"}}},
{name: "shutdown", input: `on shutdown cmd arg1 arg2 &`, shouldErr: false, config: hook.Config{Event: caddy.ShutdownEvent, Command: "cmd", Args: []string{"arg1", "arg2", "&"}}},
{name: "certrenew", input: `on certrenew cmd arg1 arg2`, shouldErr: false, config: hook.Config{Event: caddy.CertRenewEvent, Command: "cmd", Args: []string{"arg1", "arg2"}}},
}