diff options
author | Valery Piashchynski <[email protected]> | 2021-09-16 21:46:50 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2021-09-16 21:46:50 +0300 |
commit | 3581b45f237a3f7aa29591ceb2bf6f4a4642a2f5 (patch) | |
tree | e723b19ec1ac16b7ccc7b3c2da69d4a416d63d81 /plugins/service/plugin.go | |
parent | 337d292dd2d6ff0a555098b1970d8194d8df8bc2 (diff) | |
parent | 823d831b57b75f70c7c3bbbee355f2016633bb3b (diff) |
[#803]: feat(plugins): move plugins to a separate repositoryv2.5.0-alpha.2
[#803]: feat(plugins): move plugins to a separate repository
Diffstat (limited to 'plugins/service/plugin.go')
-rw-r--r-- | plugins/service/plugin.go | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/plugins/service/plugin.go b/plugins/service/plugin.go deleted file mode 100644 index 3bd0f956..00000000 --- a/plugins/service/plugin.go +++ /dev/null @@ -1,110 +0,0 @@ -package service - -import ( - "sync" - - "github.com/spiral/errors" - "github.com/spiral/roadrunner/v2/pkg/state/process" - "github.com/spiral/roadrunner/v2/plugins/config" - "github.com/spiral/roadrunner/v2/plugins/logger" -) - -const PluginName string = "service" - -type Plugin struct { - sync.Mutex - - logger logger.Logger - cfg Config - - // all processes attached to the service - processes []*Process -} - -func (service *Plugin) Init(cfg config.Configurer, log logger.Logger) error { - const op = errors.Op("service_plugin_init") - if !cfg.Has(PluginName) { - return errors.E(errors.Disabled) - } - err := cfg.UnmarshalKey(PluginName, &service.cfg.Services) - if err != nil { - return errors.E(op, err) - } - - // init default parameters if not set by user - service.cfg.InitDefault() - // save the logger - service.logger = log - - return nil -} - -func (service *Plugin) Serve() chan error { - errCh := make(chan error, 1) - - // start processing - go func() { - // lock here, because Stop command might be invoked during the Serve - service.Lock() - defer service.Unlock() - - service.processes = make([]*Process, 0, len(service.cfg.Services)) - // for the every service - for k := range service.cfg.Services { - // create needed number of the processes - for i := 0; i < service.cfg.Services[k].ProcessNum; i++ { - // create processor structure, which will process all the services - service.processes = append(service.processes, NewServiceProcess( - service.cfg.Services[k].RemainAfterExit, - service.cfg.Services[k].ExecTimeout, - service.cfg.Services[k].RestartSec, - service.cfg.Services[k].Command, - service.logger, - errCh, - )) - } - } - - // start all processes - for i := 0; i < len(service.processes); i++ { - service.processes[i].start() - } - }() - - return errCh -} - -func (service *Plugin) Workers() []process.State { - service.Lock() - defer service.Unlock() - states := make([]process.State, 0, len(service.processes)) - for i := 0; i < len(service.processes); i++ { - st, err := process.GeneralProcessState(service.processes[i].Pid, service.processes[i].rawCmd) - if err != nil { - continue - } - states = append(states, st) - } - return states -} - -func (service *Plugin) Stop() error { - service.Lock() - defer service.Unlock() - - if len(service.processes) > 0 { - for i := 0; i < len(service.processes); i++ { - service.processes[i].stop() - } - } - return nil -} - -// Name contains service name. -func (service *Plugin) Name() string { - return PluginName -} - -// Available interface implementation -func (service *Plugin) Available() { -} |