diff options
author | Wolfy-J <[email protected]> | 2018-06-11 11:46:40 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-11 11:46:40 +0300 |
commit | 4e54066384b1f2cfb6684c781976d3a9288f1f7e (patch) | |
tree | bbda59e6be6bb6bb6e95a865be839becfecf7c19 /cmd | |
parent | f1e09d869e9a177228aadb6385ad578d2e29f90d (diff) |
graceful stop
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/rr/cmd/serve.go | 6 | ||||
-rw-r--r-- | cmd/rr/main.go | 25 |
2 files changed, 23 insertions, 8 deletions
diff --git a/cmd/rr/cmd/serve.go b/cmd/rr/cmd/serve.go index 334771ae..c53f7ce9 100644 --- a/cmd/rr/cmd/serve.go +++ b/cmd/rr/cmd/serve.go @@ -37,13 +37,11 @@ func init() { }) signal.Notify(stopSignal, syscall.SIGTERM) + signal.Notify(stopSignal, syscall.SIGINT) } func serveHandler(cmd *cobra.Command, args []string) error { - if err := Container.Serve(); err != nil { - return err - } - + go Container.Serve() <-stopSignal Container.Stop() diff --git a/cmd/rr/main.go b/cmd/rr/main.go index db696904..07448feb 100644 --- a/cmd/rr/main.go +++ b/cmd/rr/main.go @@ -26,7 +26,7 @@ import ( rr "github.com/spiral/roadrunner/cmd/rr/cmd" // services (plugins) - "github.com/spiral/roadrunner/service/http" + rrhtp "github.com/spiral/roadrunner/service/http" "github.com/spiral/roadrunner/service/rpc" "github.com/spiral/roadrunner/service/static" @@ -35,16 +35,33 @@ import ( "github.com/spiral/roadrunner/cmd/rr/debug" "github.com/spf13/cobra" + _ "net/http/pprof" + "os" + "log" + "runtime/pprof" + "net/http" ) var debugMode bool func main() { + f, err := os.Create("cpu.pprof") + if err != nil { + log.Fatal(err) + } + + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + + go func() { + log.Println(http.ListenAndServe("localhost:6060", nil)) + }() + // provides ability to make local connection to services rr.Container.Register(rpc.Name, &rpc.Service{}) // http serving - rr.Container.Register(http.Name, &http.Service{}) + rr.Container.Register(rrhtp.Name, &rrhtp.Service{}) // serving static files rr.Container.Register(static.Name, &static.Service{}) @@ -55,8 +72,8 @@ func main() { rr.CLI.PersistentFlags().BoolVarP(&debugMode, "debug", "d", false, "debug mode", ) cobra.OnInitialize(func() { if debugMode { - service, _ := rr.Container.Get(http.Name) - service.(*http.Service).AddListener(debug.NewListener(rr.Logger).Listener) + service, _ := rr.Container.Get(rrhtp.Name) + service.(*rrhtp.Service).AddListener(debug.NewListener(rr.Logger).Listener) } }) |