コード例 #1
0
ファイル: main.go プロジェクト: jeffjen/ambd
func Ambassador(ctx *cli.Context) {
	var (
		addr = ctx.String("addr")

		proxycfg = ctx.String("proxycfg")

		localproxycfg = proxy.ConfigKey()

		proxyTargets = ctx.StringSlice("proxy")

		stop = make(chan struct{}, 1)
	)

	// setup register path for discovery
	disc.RegisterPath = path.Join(ctx.String("cluster"), proxy.DiscoveryPath)

	// setup Discovery URI from config
	proxy.DiscoveryURI()

	if err := dcli.Before(ctx); err != nil { // We don't want to setup discovery
		if err == dcli.ErrRequireDiscovery {
			log.WithFields(log.Fields{"err": err}).Warning("discovery feature disabled")
		} else {
			log.WithFields(log.Fields{"err": err}).Fatal("halt")
		}
	} else { // We had successfully setup discovery
		if localproxycfg != "" {
			proxy.ProxyConfigKey = localproxycfg
		} else if proxycfg != "" {
			proxy.ProxyConfigKey = proxycfg
		}
		if proxyTargets != nil {
			proxy.Targets = proxyTargets
		}
		proxy.EnableDiscoveryProxy = ctx.Bool("proxy2discovery")
		proxy.Follow()
	}

	if addr != "" {
		log.WithFields(log.Fields{"addr": addr}).Info("API endpoint begin")
		web.RunAPIEndpoint(addr, stop)
	} else {
		log.Warning("API endpoint disabled")
	}

	<-stop // we should never reach here

	// TODO: we should gracefully shutdown proxied connections
}
コード例 #2
0
ファイル: main.go プロジェクト: jeffjen/docker-monitor
func Monitor(ctx *cli.Context) {
	var (
		addr = ctx.String("addr")
		idle = ctx.Bool("idle")

		stop = make(chan struct{}, 1)
	)

	// setup register path for discovery
	disc.RegisterPath = path.Join(ctx.String("cluster"), DiscoveryPath)

	if err := dcli.Before(ctx); err != nil {
		if err == dcli.ErrRequireDiscovery {
			log.WithFields(log.Fields{"err": err}).Warning("discovery feature disabled")
		} else {
			log.WithFields(log.Fields{"err": err}).Fatal("halt")
		}
	}

	if err := scli.Before(ctx); err != nil {
		log.Error(err)
		os.Exit(1)
	}

	// setup service upkeep
	up.Init(ctx.Bool("persist"), scli.DefaultSlack)

	if addr != "" {
		log.WithFields(log.Fields{"addr": addr}).Info("API endpoint begin")
		go web.RunAPIEndpoint(addr, stop)
	} else {
		log.Warning("API endpoint disabled")
	}

	if !idle {
		log.Info("Track container life cycle")
		go dkr.RunDockerEvent(stop)
	} else {
		log.Warning("docker event endpoint disabled")
	}

	if addr != "" || !idle {
		<-stop // we should never reach pass this point
	} else {
		log.Warning("nothing to do; quit now")
	}
}