package server import ( "context" "fmt" "os" "os/exec" "strings" "unsafe" "github.com/spiral/errors" "github.com/spiral/roadrunner/v2/pkg/transport" "github.com/spiral/roadrunner/v2/plugins/config" "github.com/spiral/roadrunner/v2/plugins/logger" // core imports "github.com/spiral/roadrunner/v2/pkg/events" "github.com/spiral/roadrunner/v2/pkg/pool" "github.com/spiral/roadrunner/v2/pkg/transport/pipe" "github.com/spiral/roadrunner/v2/pkg/transport/socket" "github.com/spiral/roadrunner/v2/pkg/worker" "github.com/spiral/roadrunner/v2/utils" ) // PluginName for the server const PluginName = "server" // RR_RELAY env variable key (internal) const RR_RELAY = "RR_RELAY" //nolint:golint,stylecheck // RR_RPC env variable key (internal) if the RPC presents const RR_RPC = "RR_RPC" //nolint:golint,stylecheck // Plugin manages worker type Plugin struct { cfg Config log logger.Logger factory transport.Factory } // Init application provider. func (server *Plugin) Init(cfg config.Configurer, log logger.Logger) error { const op = errors.Op("server_plugin_init") if !cfg.Has(PluginName) { return errors.E(op, errors.Disabled) } err := cfg.Unmarshal(&server.cfg) if err != nil { return errors.E(op, errors.Init, err) } server.cfg.InitDefaults() server.log = log return nil } // Name contains service name. func (server *Plugin) Name() string { return PluginName } // Serve (Start) server plugin (just a mock here to satisfy interface) func (server *Plugin) Serve() chan error { const op = errors.Op("server_plugin_serve") errCh := make(chan error, 1) var err error server.factory, err = server.initFactory() if err != nil { errCh <- errors.E(op, err) return errCh } return errCh } // Stop used to close chosen in config factory func (server *Plugin) Stop() error { if server.factory == nil { return nil } return server.factory.Close() } // CmdFactory provides worker command factory associated with given context. func (server *Plugin) CmdFactory(env Env) (func() *exec.Cmd, error) { const op = errors.Op("server_plugin_cmd_factory") var cmdArgs []string // create command according to the config cmdArgs = append(cmdArgs, strings.Split(server.cfg.Server.Command, " ")...) if len(cmdArgs) < 2 { return nil, errors.E(op, errors.Str("minimum command should be `