summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-01-21 13:25:36 +0300
committerValery Piashchynski <[email protected]>2021-01-21 13:25:36 +0300
commit7da6c78449776e1f3c6716250bca0b712a0423a4 (patch)
treef3512de66aca2bba408485a0ea2fc936c0e4fb9b /cmd
parent0ff05b2732b4fd0783f959c94c54d7e39169f979 (diff)
Uniform all configs
Add debug server Check nil's for all plugin intialization
Diffstat (limited to 'cmd')
-rw-r--r--cmd/cli/root.go30
-rw-r--r--cmd/main.go9
2 files changed, 35 insertions, 4 deletions
diff --git a/cmd/cli/root.go b/cmd/cli/root.go
index 06a84a82..5e201daa 100644
--- a/cmd/cli/root.go
+++ b/cmd/cli/root.go
@@ -2,6 +2,7 @@ package cli
import (
"log"
+ "net/http/pprof"
"net/rpc"
"os"
"path/filepath"
@@ -12,6 +13,8 @@ import (
"github.com/spiral/roadrunner/v2/plugins/config"
+ "net/http"
+
"github.com/spf13/cobra"
"github.com/spiral/endure"
)
@@ -21,6 +24,8 @@ var (
WorkDir string
// CfgFile is path to the .rr.yaml
CfgFile string
+ // Debug mode
+ Debug bool
// Container is the pointer to the Endure container
Container *endure.Endure
cfg *config.Viper
@@ -42,7 +47,7 @@ func Execute() {
func init() {
root.PersistentFlags().StringVarP(&CfgFile, "config", "c", ".rr.yaml", "config file (default is .rr.yaml)")
root.PersistentFlags().StringVarP(&WorkDir, "WorkDir", "w", "", "work directory")
-
+ root.PersistentFlags().BoolVarP(&Debug, "debug", "d", false, "debug mode")
cobra.OnInitialize(func() {
if CfgFile != "" {
if absPath, err := filepath.Abs(CfgFile); err == nil {
@@ -70,6 +75,11 @@ func init() {
if err != nil {
panic(err)
}
+
+ // if debug mode is on - run debug server
+ if Debug {
+ runDebugServer()
+ }
})
}
@@ -99,3 +109,21 @@ func RPCClient() (*rpc.Client, error) {
return rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn)), nil
}
+
+// debug server
+func runDebugServer() {
+ mux := http.NewServeMux()
+ mux.HandleFunc("/debug/pprof/", pprof.Index)
+ mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
+ mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
+ mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
+ mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
+ srv := http.Server{
+ Addr: ":6061",
+ Handler: mux,
+ }
+
+ if err := srv.ListenAndServe(); err != nil {
+ log.Fatal(err)
+ }
+}
diff --git a/cmd/main.go b/cmd/main.go
index 56422e82..68d0cadb 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -5,9 +5,10 @@ import (
"github.com/spiral/endure"
"github.com/spiral/roadrunner/v2/cmd/cli"
- "github.com/spiral/roadrunner/v2/plugins/http"
+ httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/informer"
+ "github.com/spiral/roadrunner/v2/plugins/kv/boltdb"
"github.com/spiral/roadrunner/v2/plugins/kv/memcached"
"github.com/spiral/roadrunner/v2/plugins/kv/memory"
"github.com/spiral/roadrunner/v2/plugins/logger"
@@ -21,7 +22,7 @@ import (
func main() {
var err error
- cli.Container, err = endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel), endure.RetryOnFail(false))
+ cli.Container, err = endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel), endure.RetryOnFail(false))
if err != nil {
log.Fatal(err)
}
@@ -34,7 +35,7 @@ func main() {
// redis plugin (internal)
&redis.Plugin{},
// http server plugin
- &http.Plugin{},
+ &httpPlugin.Plugin{},
// reload plugin
&reload.Plugin{},
// informer plugin (./rr workers, ./rr workers -i)
@@ -49,6 +50,8 @@ func main() {
&memcached.Plugin{},
// in-memory kv plugin
&memory.Plugin{},
+ // boltdb driver
+ &boltdb.Plugin{},
)
if err != nil {
log.Fatal(err)