(serviceContext context.Context)
| 62 | } |
| 63 | |
| 64 | func (w *moduleService) start(serviceContext context.Context) error { |
| 65 | // wait until all startDeps are running |
| 66 | startDeps := w.startDeps(w.name) |
| 67 | for m, s := range startDeps { |
| 68 | if s == nil { |
| 69 | continue |
| 70 | } |
| 71 | |
| 72 | level.Debug(w.logger).Log("msg", "module waiting for initialization", "module", w.name, "waiting_for", m) |
| 73 | |
| 74 | err := s.AwaitRunning(serviceContext) |
| 75 | if err != nil { |
| 76 | return fmt.Errorf("failed to start %v, because it depends on module %v, which has failed: %w", w.name, m, err) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // we don't want to let this service to stop until all dependant services are stopped, |
| 81 | // so we use independent context here |
| 82 | level.Info(w.logger).Log("msg", "starting", "module", w.name) |
| 83 | err := w.service.StartAsync(context.Background()) |
| 84 | if err != nil { |
| 85 | return errors.Wrapf(err, "error starting module: %s", w.name) |
| 86 | } |
| 87 | |
| 88 | err = w.service.AwaitRunning(serviceContext) |
| 89 | if err != nil { |
| 90 | // Make sure that underlying service is stopped before returning |
| 91 | // (e.g. in case of context cancellation, AwaitRunning returns early, but service may still be starting). |
| 92 | _ = services.StopAndAwaitTerminated(context.Background(), w.service) |
| 93 | } |
| 94 | return errors.Wrapf(err, "starting module %s", w.name) |
| 95 | } |
| 96 | |
| 97 | func (w *moduleService) run(serviceContext context.Context) error { |
| 98 | // wait until service stops, or context is canceled, whatever happens first. |
nothing calls this directly
no test coverage detected