diff --git a/gosuv.go b/gosuv.go index 24068f9..43c81f0 100644 --- a/gosuv.go +++ b/gosuv.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "os" + "os/exec" "github.com/equinox-io/equinox" "github.com/urfave/cli" @@ -62,7 +63,12 @@ func actionStartServer(c *cli.Context) error { fmt.Println("added serv: ", addr) log.Fatal(http.ListenAndServe(addr, nil)) } else { - log.Fatal("Not implement daemon mode") + err := exec.Command(os.Args[0], "start-server", "--addr", addr, "-f").Start() + if err != nil { + log.Fatal(err) + } else { + log.Println("Server started") + } } return nil } diff --git a/web.go b/web.go index 10d4d71..244c54e 100644 --- a/web.go +++ b/web.go @@ -381,12 +381,18 @@ func (s *Supervisor) Close() { } func (s *Supervisor) catchExitSignal() { - c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) + sigC := make(chan os.Signal, 1) + signal.Notify(sigC, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) go func() { - sig := <-c - fmt.Printf("Got signal: %v, stopping all running process\n", sig) - s.Close() + for sig := range sigC { + if sig == syscall.SIGHUP { + log.Println("Receive SIGHUP, just ignore") + continue + } + fmt.Printf("Got signal: %v, stopping all running process\n", sig) + s.Close() + break + } os.Exit(0) }() }