mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-20 22:52:58 -05:00
* caddy: Purge event hooks after USR1 reload * caddy: Remove event hook purge logging * caddy: Remove deleteEventHook * caddy: use old event hooks in case of an unsuccessful restart * caddy: implement restoreEventHooks
This commit is contained in:
parent
ca34a3e1aa
commit
2716e272c1
2 changed files with 39 additions and 1 deletions
32
plugins.go
32
plugins.go
|
@ -39,7 +39,7 @@ var (
|
||||||
|
|
||||||
// eventHooks is a map of hook name to Hook. All hooks plugins
|
// eventHooks is a map of hook name to Hook. All hooks plugins
|
||||||
// must have a name.
|
// must have a name.
|
||||||
eventHooks = sync.Map{}
|
eventHooks = &sync.Map{}
|
||||||
|
|
||||||
// parsingCallbacks maps server type to map of directive
|
// parsingCallbacks maps server type to map of directive
|
||||||
// to list of callback functions. These aren't really
|
// to list of callback functions. These aren't really
|
||||||
|
@ -271,6 +271,36 @@ func EmitEvent(event EventName, info interface{}) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cloneEventHooks return a clone of the event hooks *sync.Map
|
||||||
|
func cloneEventHooks() *sync.Map {
|
||||||
|
c := &sync.Map{}
|
||||||
|
eventHooks.Range(func(k, v interface{}) bool {
|
||||||
|
c.Store(k, v)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// purgeEventHooks purges all event hooks from the map
|
||||||
|
func purgeEventHooks() {
|
||||||
|
eventHooks.Range(func(k, _ interface{}) bool {
|
||||||
|
eventHooks.Delete(k)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// restoreEventHooks restores eventHooks with a provided *sync.Map
|
||||||
|
func restoreEventHooks(m *sync.Map) {
|
||||||
|
// Purge old event hooks
|
||||||
|
purgeEventHooks()
|
||||||
|
|
||||||
|
// Restore event hooks
|
||||||
|
m.Range(func(k, v interface{}) bool {
|
||||||
|
eventHooks.Store(k, v)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// ParsingCallback is a function that is called after
|
// ParsingCallback is a function that is called after
|
||||||
// a directive's setup functions have been executed
|
// a directive's setup functions have been executed
|
||||||
// for all the server blocks.
|
// for all the server blocks.
|
||||||
|
|
|
@ -76,9 +76,17 @@ func trapSignalsPosix() {
|
||||||
caddyfileToUse = newCaddyfile
|
caddyfileToUse = newCaddyfile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backup old event hooks
|
||||||
|
oldEventHooks := cloneEventHooks()
|
||||||
|
|
||||||
|
// Purge the old event hooks
|
||||||
|
purgeEventHooks()
|
||||||
|
|
||||||
// Kick off the restart; our work is done
|
// Kick off the restart; our work is done
|
||||||
_, err = inst.Restart(caddyfileToUse)
|
_, err = inst.Restart(caddyfileToUse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
restoreEventHooks(oldEventHooks)
|
||||||
|
|
||||||
log.Printf("[ERROR] SIGUSR1: %v", err)
|
log.Printf("[ERROR] SIGUSR1: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue