commands: Fix server without watch - hugo - [fork] hugo port for 9front
 (HTM) git clone git@git.drkhsh.at/hugo.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 4e524ffcfff48c017717e261c6067416aa56410f
 (DIR) parent 64f0e9d1c1d4ff2249fd9cf9749e70485002b36d
 (HTM) Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Sun, 14 Jan 2018 20:58:52 +0100
       
       commands: Fix server without watch
       
       This was broken in Hugo 0.30.
       
       Fixes #4275
       
       Diffstat:
         M commands/hugo.go                    |      15 ++-------------
         M commands/server.go                  |      17 ++++++++++++++---
       
       2 files changed, 16 insertions(+), 16 deletions(-)
       ---
 (DIR) diff --git a/commands/hugo.go b/commands/hugo.go
       @@ -30,7 +30,6 @@ import (
                "path/filepath"
                "runtime"
                "strings"
       -        "sync"
                "time"
        
                src "github.com/gohugoio/hugo/source"
       @@ -633,7 +632,7 @@ func (c *commandeer) build(watches ...bool) error {
                        }
                        c.Logger.FEEDBACK.Println("Watching for changes in", c.PathSpec().AbsPathify(c.Cfg.GetString("contentDir")))
                        c.Logger.FEEDBACK.Println("Press Ctrl+C to stop")
       -                utils.CheckErr(c.Logger, c.newWatcher(false, watchDirs...))
       +                utils.CheckErr(c.Logger, c.newWatcher(watchDirs...))
                }
        
                return nil
       @@ -969,9 +968,7 @@ func (c *commandeer) rebuildSites(events []fsnotify.Event) error {
        }
        
        // newWatcher creates a new watcher to watch filesystem events.
       -// if serve is set it will also start one or more HTTP servers to serve those
       -// files.
       -func (c *commandeer) newWatcher(serve bool, dirList ...string) error {
       +func (c *commandeer) newWatcher(dirList ...string) error {
                if runtime.GOOS == "darwin" {
                        tweakLimit()
                }
       @@ -982,7 +979,6 @@ func (c *commandeer) newWatcher(serve bool, dirList ...string) error {
                }
        
                watcher, err := watcher.New(1 * time.Second)
       -        var wg sync.WaitGroup
        
                if err != nil {
                        return err
       @@ -990,8 +986,6 @@ func (c *commandeer) newWatcher(serve bool, dirList ...string) error {
        
                defer watcher.Close()
        
       -        wg.Add(1)
       -
                for _, d := range dirList {
                        if d != "" {
                                _ = watcher.Add(d)
       @@ -1189,11 +1183,6 @@ func (c *commandeer) newWatcher(serve bool, dirList ...string) error {
                        }
                }()
        
       -        if serve {
       -                go c.serve()
       -        }
       -
       -        wg.Wait()
                return nil
        }
        
 (DIR) diff --git 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