summaryrefslogtreecommitdiffstats
path: root/commands/server.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-15 21:01:36 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-15 22:58:05 +0200
commit87a22eb6d609a65471ccf4de35a558e9669a4600 (patch)
tree229a520a61dac3c772104ab720613671d978f046 /commands/server.go
parentfc9f315d86e1fe51c3d1eec3b60680113b2e3aa6 (diff)
server: Fix SIGINT handling after loading bad configuration
Also fix the config error messages. Fixes #9664
Diffstat (limited to 'commands/server.go')
-rw-r--r--commands/server.go47
1 files changed, 35 insertions, 12 deletions
diff --git a/commands/server.go b/commands/server.go
index f61681003..a339a1760 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -522,18 +522,20 @@ func (c *commandeer) serve(s *serverCmd) error {
roots = []string{""}
}
+ templHandler := c.hugo().Tmpl()
+ errTempl, found := templHandler.Lookup("_server/error.html")
+ if !found {
+ panic("template server/error.html not found")
+ }
+
srv := &fileServer{
baseURLs: baseURLs,
roots: roots,
c: c,
s: s,
errorTemplate: func(ctx any) (io.Reader, error) {
- templ, found := c.hugo().Tmpl().Lookup("_server/error.html")
- if !found {
- panic("template server/error.html not found")
- }
b := &bytes.Buffer{}
- err := c.hugo().Tmpl().Execute(templ, b, ctx)
+ err := templHandler.Execute(errTempl, b, ctx)
return b, err
},
}
@@ -579,16 +581,37 @@ func (c *commandeer) serve(s *serverCmd) error {
jww.FEEDBACK.Println("Press Ctrl+C to stop")
- if s.stop != nil {
- select {
- case <-sigs:
- case <-s.stop:
+ err := func() error {
+ if s.stop != nil {
+ for {
+ select {
+ case <-sigs:
+ return nil
+ case <-s.stop:
+ return nil
+ case <-ctx.Done():
+ return ctx.Err()
+ }
+ }
+ } else {
+ for {
+ select {
+ case <-sigs:
+ return nil
+ case <-ctx.Done():
+ return ctx.Err()
+ }
+ }
}
- } else {
- <-sigs
+ }()
+
+ if err != nil {
+ jww.ERROR.Println("Error:", err)
}
- c.hugo().Close()
+ if h := c.hugoTry(); h != nil {
+ h.Close()
+ }
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()