Ejemplo n.º 1
0
func main() {
	log.Println("===> Start running daemon")
	wg := &sync.WaitGroup{}
	wg.Add(2)
	//Init Docker client
	client, err := connectToDocker()
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	log.Println("===> Starting container discovery goroutine")
	go containerThread(client, wg)

	tries := 0
	if nodes.Node_Api_Uri != "" {
		dockercloud.SetUserAgent("network-daemon/" + Version)
	Loop:
		for {
			node, err := dockercloud.GetNode(nodes.Node_Api_Uri)
			if err != nil {
				tries++
				log.Println(err)
				time.Sleep(5 * time.Second)
				if tries > 3 {
					time.Sleep(60 * time.Second)
					tries = 0
				}
				continue Loop
			} else {
				nodes.Region = node.Region
				nodes.Node_Public_Ip = node.Public_ip
				nodes.Node_Uuid = node.Uuid

				log.Println("===> Posting interface data to database")
				nodes.PostInterfaceData(os.Getenv("DOCKERCLOUD_REST_HOST") + nodes.Node_Api_Uri)

				log.Printf("This node IP is %s", nodes.Node_Public_Ip)
				if os.Getenv("DOCKERCLOUD_AUTH") != "" {
					log.Println("===> Detected Dockecloud API access - starting peer discovery goroutine")
					go discovering(wg)
					break Loop
				}
			}
		}
	}
	wg.Wait()
}
Ejemplo n.º 2
0
func main() {
	log.Println("===> Start running daemon")
	wg := &sync.WaitGroup{}
	wg.Add(1)

	counter := 0
	if nodes.NodeAPIURI != "" {
		dockercloud.SetUserAgent("network-daemon/" + tools.Version)
	Loop:
		for {
			node, err := dockercloud.GetNode(nodes.NodeAPIURI)
			if err != nil {
				e, ok := err.(dockercloud.HttpError)
				if ok && e.StatusCode == 401 {
					log.Println("Not authorized. Retry in 1 hour")
					time.Sleep(1 * time.Hour)
					break
				}
				log.Print(strings.ToLower(err.Error()))
				if counter > 100 {
					time.Sleep(time.Duration(counter) * time.Second)
					counter = 0
				} else {
					counter *= 2
					log.Println(err)
					time.Sleep(5 * time.Second)
				}
			} else {
				nodes.Region = node.Region
				nodes.NodePublicIP = node.Public_ip
				nodes.NodeUUID = node.Uuid

				log.Println("===> Posting interface data to database")
				nodes.PostInterfaceData(os.Getenv("DOCKERCLOUD_REST_HOST") + nodes.NodeAPIURI)

				log.Printf("This node IP is %s", nodes.NodePublicIP)
				if os.Getenv("DOCKERCLOUD_AUTH") != "" {
					log.Println("===> Detected Dockecloud API access - starting peer discovery goroutine")
					go discovering(wg)
					break Loop
				}
			}
		}
	}
	wg.Wait()
}