package server import ( "context" "fmt" "os" "os/exec" "strings" "github.com/spiral/errors" "github.com/spiral/roadrunner/v2/plugins/config" "github.com/spiral/roadrunner/v2/plugins/logger" // core imports "github.com/spiral/roadrunner/v2/interfaces/events" "github.com/spiral/roadrunner/v2/interfaces/pool" "github.com/spiral/roadrunner/v2/interfaces/worker" "github.com/spiral/roadrunner/v2/pkg/pipe" poolImpl "github.com/spiral/roadrunner/v2/pkg/pool" "github.com/spiral/roadrunner/v2/pkg/socket" "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 = "" //nolint:golint,stylecheck // RR_HTTP env variable key (internal) if the HTTP presents const RR_HTTP = "false" //nolint:golint,stylecheck // Plugin manages worker type Plugin struct { cfg Config log logger.Logger factory worker.Factory } // Init application provider. func (server *Plugin) Init(cfg config.Configurer, log logger.Logger) error { const op = errors.Op("Init") err := cfg.Unmarshal(&server.cfg) if err != nil { return errors.E(op, errors.Init, err) } server.cfg.InitDefaults() server.log = log server.factory, err = server.initFactory() if err != nil { return errors.E(err) } 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 { errCh := make(chan error, 1) 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("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("should be in form of `php