add daemon mode

master
codeskyblue 8 years ago
parent 936a83b115
commit 960eb28054

@ -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
}

@ -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)
}()
}

Loading…
Cancel
Save