mirror of
https://github.com/caddyserver/caddy.git
synced 2025-12-08 06:09:53 +00:00
core: Major refactor of admin endpoint and config handling
Fixed several bugs and made other improvements. All config changes are now mediated by the global config state manager. It used to be that initial configs given at startup weren't tracked, so you could start caddy with --config caddy.json and then do a GET /config/ and it would return null. That is fixed, along with several other general flow/API enhancements, with more to come.
This commit is contained in:
parent
fb06c041c4
commit
35f70c98fa
8 changed files with 962 additions and 683 deletions
|
|
@ -160,23 +160,12 @@ func cmdRun(fl Flags) (int, error) {
|
|||
cleanModVersion := strings.TrimPrefix(goModule.Version, "v")
|
||||
certmagic.UserAgent = "Caddy/" + cleanModVersion
|
||||
|
||||
// start the admin endpoint along with any initial config
|
||||
// a configuration without admin config is considered fine
|
||||
// but does not enable the admin endpoint at all
|
||||
err = caddy.StartAdmin(config)
|
||||
if err == nil {
|
||||
defer caddy.StopAdmin()
|
||||
} else if err != caddy.ErrAdminInterfaceNotConfigured {
|
||||
return caddy.ExitCodeFailedStartup,
|
||||
fmt.Errorf("starting caddy administration endpoint: %v", err)
|
||||
// run the initial config
|
||||
err = caddy.Load(config, true)
|
||||
if err != nil {
|
||||
return caddy.ExitCodeFailedStartup, fmt.Errorf("loading initial config: %v", err)
|
||||
}
|
||||
|
||||
// if a config has been supplied, load it as initial config
|
||||
if len(config) > 0 {
|
||||
err := caddy.Load(bytes.NewReader(config))
|
||||
if err != nil {
|
||||
return caddy.ExitCodeFailedStartup, fmt.Errorf("loading initial config: %v", err)
|
||||
}
|
||||
caddy.Log().Named("admin").Info("Caddy 2 serving initial configuration")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue