package server import ( "context" "fmt" "os" "os/exec" "strings" "github.com/spiral/errors" "github.com/spiral/roadrunner/v2/interfaces/events" "github.com/spiral/roadrunner/v2/interfaces/log" "github.com/spiral/roadrunner/v2/interfaces/pool" "github.com/spiral/roadrunner/v2/interfaces/server" "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/plugins/config" "github.com/spiral/roadrunner/v2/util" ) const PluginName = "server" // Plugin manages worker type Plugin struct { cfg Config log log.Logger factory worker.Factory } // Init application provider. func (server *Plugin) Init(cfg config.Configurer, log log.Logger) error { const op = errors.Op("Init") err := cfg.UnmarshalKey(PluginName, &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(errors.Op("Init factory"), err) } return nil } // Name contains service name. func (server *Plugin) Name() string { return PluginName } func (server *Plugin) Serve() chan error { errCh := make(chan error, 1) return errCh } func (server *Plugin) Stop() error { if server.factory == nil { return nil } return server.factory.Close(context.Background()) } // CmdFactory provides worker command factory assocated with given context. func (server *Plugin) CmdFactory(env server.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.Command, " ")...) if len(cmdArgs) < 2 { return nil, errors.E(op, errors.Str("should be in form of `php