github.com/greenboxal/deis@v1.12.1/publisher/main.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"log"
     6  	"net/http"
     7  	_ "net/http/pprof"
     8  	"time"
     9  
    10  	"github.com/coreos/go-etcd/etcd"
    11  	"github.com/fsouza/go-dockerclient"
    12  
    13  	"github.com/deis/deis/publisher/server"
    14  )
    15  
    16  const (
    17  	defaultRefreshTime time.Duration = 10 * time.Second
    18  	defaultEtcdTTL     time.Duration = defaultRefreshTime * 2
    19  	defaultHost                      = "127.0.0.1"
    20  	defaultDockerHost                = "unix:///var/run/docker.sock"
    21  	defaultEtcdHost                  = "127.0.0.1"
    22  	defaultEtcdPort                  = "4001"
    23  	defaultLogLevel                  = "error"
    24  )
    25  
    26  var (
    27  	refreshDuration = flag.Duration("refresh-duration", defaultRefreshTime, "The time to wait between etcd refreshes.")
    28  	etcdTTL         = flag.Duration("etcd-ttl", defaultEtcdTTL, "The TTL for all of the keys in etcd.")
    29  	host            = flag.String("host", defaultHost, "The host where the publisher is running.")
    30  	dockerHost      = flag.String("docker-host", defaultDockerHost, "The host where to find docker.")
    31  	etcdHost        = flag.String("etcd-host", defaultEtcdHost, "The etcd host.")
    32  	etcdPort        = flag.String("etcd-port", defaultEtcdPort, "The etcd port.")
    33  	logLevel        = flag.String("log-level", defaultLogLevel, "Acceptable values: error, debug")
    34  )
    35  
    36  func main() {
    37  	flag.Parse()
    38  
    39  	dockerClient, err := docker.NewClient(*dockerHost)
    40  	if err != nil {
    41  		log.Fatal(err)
    42  	}
    43  	etcdClient := etcd.NewClient([]string{"http://" + *etcdHost + ":" + *etcdPort})
    44  
    45  	server := server.New(dockerClient, etcdClient, *host, *logLevel)
    46  
    47  	go server.Listen(*etcdTTL)
    48  
    49  	go func() {
    50  		log.Println(http.ListenAndServe("localhost:6060", nil))
    51  	}()
    52  
    53  	for {
    54  		go server.Poll(*etcdTTL)
    55  		time.Sleep(*refreshDuration)
    56  	}
    57  }