Example #1
0
func (s *Service) watchChanges() {
	go s.configurator.WatchChanges(s.changeC)
	err := s.backend.WatchChanges(s.changeC, true)
	if err != nil {
		log.Infof("Stopped watching changes with error: %s. Shutting down with error", err)
		s.errorC <- err
	} else {
		log.Infof("Stopped watching changes without error. Will continue running", err)
	}
}
Example #2
0
func (s *Service) Start() error {
	log.Init([]*log.LogConfig{&log.LogConfig{Name: s.options.Log}})

	backend, err := etcdbackend.NewEtcdBackend(
		s.registry, s.options.EtcdNodes, s.options.EtcdKey, s.options.EtcdConsistency, &timetools.RealTime{})
	if err != nil {
		return err
	}
	s.backend = backend

	if s.options.PidPath != "" {
		if err := runtime.WritePid(s.options.PidPath); err != nil {
			return fmt.Errorf("failed to write PID file: %v\n", err)
		}
	}

	if err := s.createProxy(); err != nil {
		return err
	}

	go func() {
		s.errorC <- s.startProxy()
	}()

	s.configurator = configure.NewConfiguratorWithOptions(s.proxy, configure.Options{
		DialTimeout: s.options.EndpointDialTimeout,
		ReadTimeout: s.options.EndpointReadTimeout,
	})

	// Tell backend to watch configuration changes and pass them to the channel
	// the second parameter tells backend to do the initial read of the configuration
	// and produce the stream of changes so proxy would initialise initial config
	go s.watchChanges()

	if err := s.initApi(); err != nil {
		return err
	}

	go func() {
		s.errorC <- s.startApi()
	}()

	signal.Notify(s.sigC, os.Interrupt, os.Kill, syscall.SIGTERM)

	// Block until a signal is received or we got an error
	select {
	case signal := <-s.sigC:
		log.Infof("Got signal %s, exiting now", signal)
		return nil
	case err := <-s.errorC:
		log.Infof("Got request to shutdown with error: %s", err)
		return err
	}
	return nil
}
Example #3
0
func Run(registry *plugin.Registry) error {
	options, err := ParseCommandLine()
	if err != nil {
		return fmt.Errorf("Failed to parse command line: %s", err)
	}
	service := NewService(options, registry)
	if err := service.Start(); err != nil {
		return fmt.Errorf("Service exited with error: %s", err)
	} else {
		log.Infof("Service exited gracefully")
	}
	return nil
}
Example #4
0
func (we *WeightedEndpoint) setEffectiveWeight(w int) {
	log.Infof("%s setting effective weight to: %d", we, w)
	we.effectiveWeight = w
}