summaryrefslogtreecommitdiffhomepage
path: root/commands/server.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2018-01-14 20:58:52 +0100
committerBjørn Erik Pedersen <[email protected]>2018-01-14 20:58:52 +0100
commit4e524ffcfff48c017717e261c6067416aa56410f (patch)
tree57a3819be5e61defe3e5237460fd1a7054958aa8 /commands/server.go
parent64f0e9d1c1d4ff2249fd9cf9749e70485002b36d (diff)
downloadhugo-4e524ffcfff48c017717e261c6067416aa56410f.tar.gz
hugo-4e524ffcfff48c017717e261c6067416aa56410f.zip
commands: Fix server without watch
This was broken in Hugo 0.30. Fixes #4275
Diffstat (limited to 'commands/server.go')
-rw-r--r--commands/server.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/commands/server.go b/commands/server.go
index 21137619d..b9f21783b 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -19,10 +19,12 @@ import (
"net/http"
"net/url"
"os"
+ "os/signal"
"path/filepath"
"runtime"
"strconv"
"strings"
+ "syscall"
"time"
"github.com/gohugoio/hugo/livereload"
@@ -229,14 +231,16 @@ func server(cmd *cobra.Command, args []string) error {
rootWatchDirs := strings.Join(helpers.UniqueStrings(helpers.ExtractRootPaths(relWatchDirs)), ",")
jww.FEEDBACK.Printf("Watching for changes in %s%s{%s}\n", baseWatchDir, helpers.FilePathSeparator, rootWatchDirs)
- err = c.newWatcher(true, watchDirs...)
+ err = c.newWatcher(watchDirs...)
if err != nil {
return err
}
+
}
- return nil
+ return c.serve()
+
}
type fileServer struct {
@@ -313,7 +317,7 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, string, string, erro
return mu, u.String(), endpoint, nil
}
-func (c *commandeer) serve() {
+func (c *commandeer) serve() error {
isMultiHost := Hugo.IsMultihost()
@@ -345,6 +349,9 @@ func (c *commandeer) serve() {
livereload.Initialize()
}
+ var sigs = make(chan os.Signal)
+ signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
+
for i, _ := range baseURLs {
mu, serverURL, endpoint, err := srv.createEndpoint(i)
@@ -363,6 +370,10 @@ func (c *commandeer) serve() {
}
jww.FEEDBACK.Println("Press Ctrl+C to stop")
+
+ <-sigs
+
+ return nil
}
// fixURL massages the baseURL into a form needed for serving