Run starts the component, and returns when a stop signal has been received by the process.
()
| 394 | |
| 395 | // Run starts the component, and returns when a stop signal has been received by the process. |
| 396 | func (c *Component) Run() error { |
| 397 | defer c.Close() |
| 398 | |
| 399 | if err := c.Start(); err != nil { |
| 400 | return err |
| 401 | } |
| 402 | |
| 403 | defer func() { |
| 404 | c.logger.Debug("Leaving cluster...") |
| 405 | if err := c.cluster.Leave(); err != nil { |
| 406 | c.logger.WithError(err).Error("Could not leave cluster") |
| 407 | } |
| 408 | c.logger.Debug("Left cluster") |
| 409 | }() |
| 410 | |
| 411 | signal.Notify(c.terminationSignals, os.Interrupt, syscall.SIGTERM) |
| 412 | |
| 413 | sig := <-c.terminationSignals |
| 414 | fmt.Println() |
| 415 | c.logger.WithField("signal", sig).Info("Received signal, exiting...") |
| 416 | return nil |
| 417 | } |
| 418 | |
| 419 | // Close closes the server. |
| 420 | func (c *Component) Close() { |