mirror of
https://github.com/caddyserver/caddy.git
synced 2026-08-04 14:58:47 +00:00
OnFirstStartup and OnFinalShutdown callbacks added
OnStartup and OnShutdown callbacks now run as part of restarts, too. The startup and shutdown directives only run their commands NOT as part of restarts, as before. Some middleware that use OnStartup may need to switch to OnFirstStartup and implement OnFinalShutdown to do any cleanup as needed.
This commit is contained in:
parent
b49f65d5de
commit
15fa5cf2da
8 changed files with 73 additions and 16 deletions
|
|
@ -54,8 +54,14 @@ func (c *Controller) ServerType() string {
|
|||
return c.instance.serverType
|
||||
}
|
||||
|
||||
// OnFirstStartup adds fn to the list of callback functions to execute
|
||||
// when the server is about to be started NOT as part of a restart.
|
||||
func (c *Controller) OnFirstStartup(fn func() error) {
|
||||
c.instance.onFirstStartup = append(c.instance.onFirstStartup, fn)
|
||||
}
|
||||
|
||||
// OnStartup adds fn to the list of callback functions to execute
|
||||
// when the server is about to be started.
|
||||
// when the server is about to be started (including restarts).
|
||||
func (c *Controller) OnStartup(fn func() error) {
|
||||
c.instance.onStartup = append(c.instance.onStartup, fn)
|
||||
}
|
||||
|
|
@ -67,11 +73,17 @@ func (c *Controller) OnRestart(fn func() error) {
|
|||
}
|
||||
|
||||
// OnShutdown adds fn to the list of callback functions to execute
|
||||
// when the server is about to be shut down..
|
||||
// when the server is about to be shut down (including restarts).
|
||||
func (c *Controller) OnShutdown(fn func() error) {
|
||||
c.instance.onShutdown = append(c.instance.onShutdown, fn)
|
||||
}
|
||||
|
||||
// OnFinalShutdown adds fn to the list of callback functions to execute
|
||||
// when the server is about to be shut down NOT as part of a restart.
|
||||
func (c *Controller) OnFinalShutdown(fn func() error) {
|
||||
c.instance.onFinalShutdown = append(c.instance.onFinalShutdown, fn)
|
||||
}
|
||||
|
||||
// Context gets the context associated with the instance associated with c.
|
||||
func (c *Controller) Context() Context {
|
||||
return c.instance.context
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue