diff options
author | Seb <[email protected]> | 2022-07-14 16:07:50 +0200 |
---|---|---|
committer | Seb <[email protected]> | 2022-07-15 13:27:45 +0200 |
commit | d755a74819640ccc14a110b6b4025aebd4fdc20c (patch) | |
tree | 9a326f381e6784e90e907d40168c89bd6845191e /internal | |
parent | 4b8400b4d5041bd6fd06715d9d8f00464f8b8424 (diff) |
- revert command changes
- fix error style
- create module with own go.mod / go.sum
Diffstat (limited to 'internal')
-rw-r--r-- | internal/cli/serve/command.go | 62 |
1 files changed, 51 insertions, 11 deletions
diff --git a/internal/cli/serve/command.go b/internal/cli/serve/command.go index 07e346b2..73b54c3c 100644 --- a/internal/cli/serve/command.go +++ b/internal/cli/serve/command.go @@ -6,8 +6,10 @@ import ( "os/signal" "syscall" - "github.com/roadrunner-server/roadrunner/v2/roadrunner" + "github.com/roadrunner-server/roadrunner/v2/internal/container" + "github.com/roadrunner-server/roadrunner/v2/internal/meta" + configImpl "github.com/roadrunner-server/config/v2" "github.com/roadrunner-server/errors" "github.com/spf13/cobra" ) @@ -23,19 +25,53 @@ func NewCommand(override *[]string, cfgFile *string, silent *bool) *cobra.Comman Short: "Start RoadRunner server", RunE: func(*cobra.Command, []string) error { const op = errors.Op("handle_serve_command") - rr, err := roadrunner.NewRR(*cfgFile, override, roadrunner.DefaultPluginsList()) + // just to be safe + if cfgFile == nil { + return errors.E(op, errors.Str("no configuration file provided")) + } + // create endure container config + containerCfg, err := container.NewConfig(*cfgFile) if err != nil { return errors.E(op, err) } - errCh := make(chan error, 1) - go func() { - err = rr.Serve() - if err != nil { - errCh <- errors.E(op, err) + cfg := &configImpl.Plugin{ + Path: *cfgFile, + Prefix: rrPrefix, + Timeout: containerCfg.GracePeriod, + Flags: *override, + Version: meta.Version(), + } + + // create endure container + endureContainer, err := container.NewContainer(*containerCfg) + if err != nil { + return errors.E(op, err) + } + + // register config plugin + if err = endureContainer.Register(cfg); err != nil { + return errors.E(op, err) + } + + // register another container plugins + for i, plugins := 0, container.Plugins(); i < len(plugins); i++ { + if err = endureContainer.Register(plugins[i]); err != nil { + return errors.E(op, err) } - }() + } + + // init container and all services + if err = endureContainer.Init(); err != nil { + return errors.E(op, err) + } + + // start serving the graph + errCh, err := endureContainer.Serve() + if err != nil { + return errors.E(op, err) + } oss, stop := make(chan os.Signal, 5), make(chan struct{}, 1) //nolint:gomnd signal.Notify(oss, os.Interrupt, syscall.SIGTERM, syscall.SIGINT) @@ -53,14 +89,18 @@ func NewCommand(override *[]string, cfgFile *string, silent *bool) *cobra.Comman os.Exit(1) }() + if !*silent { + fmt.Printf("[INFO] RoadRunner server started; version: %s, buildtime: %s\n", meta.Version(), meta.BuildTime()) + } + for { select { case e := <-errCh: - return errors.E(op, e) + return fmt.Errorf("error: %w\nplugin: %s", e.Error, e.VertexID) case <-stop: // stop the container after first signal - fmt.Printf("stop signal received\n") + fmt.Printf("stop signal received, grace timeout is: %0.f seconds\n", containerCfg.GracePeriod.Seconds()) - if err = rr.Stop(); err != nil { + if err = endureContainer.Stop(); err != nil { return fmt.Errorf("error: %w", err) } |