Example #1
0
File: main.go Project: gpxl/deis
func main() {
	flag.Parse()

	client := etcd.NewClient([]string{"http://" + publishHost + ":" + publishPort})

	signalChan := make(chan os.Signal, 1)
	drainChan := make(chan string)
	stopChan := make(chan bool)
	exitChan := make(chan bool)
	cleanupChan := make(chan bool)
	signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGINT)

	// ensure the drain key exists in etcd.
	if _, err := client.Get(publishPath+"/drain", false, false); err != nil {
		setEtcd(client, publishPath+"/drain", drainURI, 0)
	}

	go syslogd.Listen(exitChan, cleanupChan, drainChan, fmt.Sprintf("%s:%d", logAddr, logPort))
	if enablePublish {
		go publishService(exitChan, client, publishHost, publishPath, strconv.Itoa(logPort), uint64(time.Duration(publishTTL)*time.Second))
	}

	// HACK (bacongobbler): poll etcd for changes in the log drain value
	// etcd's .Watch() implementation is broken when you use TTLs
	//
	// https://github.com/coreos/etcd/issues/2679
	go func() {
		for {
			resp, err := client.Get(publishPath+"/drain", false, false)
			if err != nil {
				log.Printf("warning: could not retrieve drain URI from etcd: %v\n", err)
				continue
			}
			if resp != nil && resp.Node != nil {
				drainChan <- resp.Node.Value
			}
			time.Sleep(time.Duration(publishInterval) * time.Second)
		}
	}()

	for {
		select {
		case <-signalChan:
			close(exitChan)
			stopChan <- true
		case <-cleanupChan:
			return
		}
	}
}
Example #2
0
func main() {
	host := getopt("HOST", "127.0.0.1")

	etcdPort := getopt("ETCD_PORT", "4001")
	etcdPath := getopt("ETCD_PATH", "/deis/logs")

	externalPort := getopt("EXTERNAL_PORT", "514")

	client := etcd.NewClient([]string{"http://" + host + ":" + etcdPort})

	// Wait for terminating signal
	exitChan := make(chan os.Signal, 2)
	cleanupChan := make(chan bool)
	signal.Notify(exitChan, syscall.SIGTERM, syscall.SIGINT)

	go syslogd.Listen(exitChan, cleanupChan)

	go publishService(client, host, etcdPath, externalPort, uint64(ttl.Seconds()))

	// Wait for the proper shutdown of the syslog server before exit
	<-cleanupChan
}