Example #1
0
// createStoreClient is used to create a storage client based
// on our configuration. Either an etcd or Consul client.
func createStoreClient() (template.StoreClient, error) {
	if config.Consul() {
		log.Notice("Consul address set to " + config.ConsulAddr())
		return consul.NewConsulClient(config.ConsulAddr())
	} else {
		// Create the etcd client upfront and use it for the life of the process.
		// The etcdClient is an http.Client and designed to be reused.
		log.Notice("etcd nodes set to " + strings.Join(config.EtcdNodes(), ", "))
		return etcdutil.NewEtcdClient(config.EtcdNodes(), config.ClientCert(), config.ClientKey(), config.ClientCaKeys())
	}
}
Example #2
0
// createStoreClient is used to create a storage client based
// on our configuration. Either an etcd or Consul client.
func createStoreClient(backend string) (template.StoreClient, error) {
	log.Notice("Backend set to " + backend)
	switch backend {
	case "consul":
		log.Notice("Consul address set to " + config.ConsulAddr())
		return consul.NewConsulClient(config.ConsulAddr())
	case "etcd":
		// Create the etcd client upfront and use it for the life of the process.
		// The etcdClient is an http.Client and designed to be reused.
		log.Notice("etcd nodes set to " + strings.Join(config.EtcdNodes(), ", "))
		return etcdutil.NewEtcdClient(config.EtcdNodes(), config.ClientCert(), config.ClientKey(), config.ClientCaKeys())
	case "env":
		return env.NewEnvClient()
	}
	return nil, errors.New("Invalid backend")
}
Example #3
0
func main() {
	// Most flags are defined in the confd/config package which allows us to
	// override configuration settings from the command line. Parse the flags now
	// to make them active.
	flag.Parse()
	if configFile == "" {
		if IsFileExist(defaultConfigFile) {
			configFile = defaultConfigFile
		}
	}
	// Initialize the global configuration.
	log.Debug("Loading confd configuration")
	if err := config.LoadConfig(configFile); err != nil {
		log.Fatal(err.Error())
	}
	// Configure logging. While you can enable debug and verbose logging, however
	// if quiet is set to true then debug and verbose messages will not be printed.
	log.SetQuiet(config.Quiet())
	log.SetVerbose(config.Verbose())
	log.SetDebug(config.Debug())
	log.Notice("Starting confd")
	// Create the etcd client upfront and use it for the life of the process.
	// The etcdClient is an http.Client and designed to be reused.
	log.Notice("etcd nodes set to " + strings.Join(config.EtcdNodes(), ", "))
	etcdClient, err := etcdutil.NewEtcdClient(config.EtcdNodes(), config.ClientCert(), config.ClientKey(), config.ClientCaKeys())
	if err != nil {
		log.Fatal(err.Error())
	}
	for {
		runErrors := template.ProcessTemplateResources(etcdClient)
		// If the -onetime flag is passed on the command line we immediately exit
		// after processing the template config files.
		if onetime {
			if len(runErrors) > 0 {
				os.Exit(1)
			}
			os.Exit(0)
		}
		time.Sleep(time.Duration(config.Interval()) * time.Second)
	}
}