Example #1
0
func main() {
	log.Infof("flux agent version %s", version.Version())
	var (
		hostIP string
	)
	flag.StringVar(&hostIP, "host-ip", "", "IP address for instances with mapped ports")
	flag.Parse()

	dc, err := setupDockerClient()
	if err != nil {
		log.Fatalf("Error connecting to docker: %s", err)
	}

	hostIpFrom := "argument"

	if hostIP == "" {
		hostIP = os.Getenv("HOST_IP")
		hostIpFrom = `$HOST_IP in environment`
	}

	if hostIP == "" {
		hostname, err := os.Hostname()
		if err != nil {
			log.Fatalf("Unable to determine host IP via hostname: %s", err)
		}
		ip, err := net.ResolveIPAddr("ip", hostname)
		if err != nil {
			log.Fatalf("Unable to determine host IP via hostname: %s", err)
		}
		hostIP = ip.String()
		hostIpFrom = fmt.Sprintf(`resolving hostname '%s'`, hostname)
	}

	log.Infof(`Using host IP address '%s' from %s`, hostIP, hostIpFrom)

	store, err := etcdstore.NewFromEnv()
	if err != nil {
		log.Fatal(err)
	}

	listener := agent.NewListener(agent.Config{
		HostIP:    hostIP,
		Store:     store,
		Inspector: dc,
	})

	events := make(chan *docker.APIEvents)
	if err := dc.AddEventListener(events); err != nil {
		log.Fatalf("Unable to add listener to Docker API: %s", err)
	}

	if err := listener.ReadExistingContainers(); err != nil {
		log.Fatalf("Error reading existing containers: %s", err)
	}
	if err := listener.ReadInServices(); err != nil {
		log.Fatalf("Error reading configuration: %s", err)
	}
	listener.Run(events)
}
Example #2
0
func main() {
	store, err := etcdstore.NewFromEnv()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	var topCmd = &cobra.Command{
		Use:   "fluxctl",
		Short: "control flux",
		Long:  `Define services and enrol instances in them`,
	}
	addSubCommands(topCmd, store)

	if err := topCmd.Execute(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
Example #3
0
func main() {
	log.Printf("flux web version %s\n", version.Version())
	prom := os.Getenv("PROMETHEUS_ADDRESS")
	if prom == "" {
		prom = "http://localhost:9090"
	}

	store, err := etcdstore.NewFromEnv()
	if err != nil {
		log.Fatal(err)
	}

	if err := store.Ping(); err != nil {
		log.Fatal(err)
	}

	log.Printf("Connected to backend\n")
	api := &api{store, prom}

	http.ListenAndServe("0.0.0.0:7070", api.router())
}
Example #4
0
func (a *BalancerAgent) parseArgs(args []string) error {
	fs := flag.NewFlagSet(args[0], flag.ContinueOnError)

	fs.StringVar(&a.filename, "o", "/tmp/services",
		"name of file to generate")
	var templateFile string
	fs.StringVar(&templateFile, "i", "nginx.tmpl",
		"name of template file with which to generate the output file")
	fs.StringVar(&a.reloadCmd, "c", "",
		"command to run each time the file is regenerated")

	var err error
	if err = fs.Parse(args[1:]); err != nil {
		return err
	}

	a.template, err = template.ParseFiles(templateFile)
	if err != nil {
		return fmt.Errorf(`unable to parse file "%s": %s`, templateFile, err)
	}

	a.store, err = etcdstore.NewFromEnv()
	return err
}