Ejemplo n.º 1
0
// Listen for updated docker.State, compile to config.Config and update config.Writer.
//
// Stops on os.Signal
func run(configWriter *config.Writer, dockerListen chan docker.State, stopChan chan os.Signal) {
	defer stop(configWriter)

	for {
		select {
		case dockerState, ok := <-dockerListen:
			if !ok {
				// docker quit? exit and restart
				log.Printf("Stopping on Docker close...")
				return
			}

			if config, err := makeConfig(dockerState); err != nil {
				log.Fatalf("configContainers: %v", err)
			} else if err := configWriter.Write(config); err != nil {
				log.Fatalf("config:Writer.Write: %v", err)
			} else {
				log.Printf("Update config...")
			}

		case s := <-stopChan:
			log.Printf("Stopping on %v...", s)

			// reset signal in case stopping gets stuck
			signal.Stop(stopChan)

			return
		}
	}
}
Ejemplo n.º 2
0
// Flush service backends when stopping
func stop(configWriter *config.Writer) {
	log.Printf("Flush.....")

	if err := configWriter.Flush(); err != nil {
		log.Fatalf("config:Writer.Flush: %v", err)
	} else {
		log.Printf("Flushed")
	}
}