Пример #1
0
func main() {
	kingpin.Version(romulus.Version())
	kingpin.Parse()
	if *db {
		LogLevel("debug")
	} else {
		LogLevel(*lv)
	}
	if *ed {
		romulus.DebugEtcd()
	}

	eps := []string{}
	kcc := romulus.KubeClientConfig{
		Host:     (*km).String(),
		Username: *ku,
		Password: *kp,
		Insecure: true,
	}
	for _, e := range *ep {
		eps = append(eps, e.String())
	}
	if *kc != "" {
		b, _ := ioutil.ReadFile(*kc)
		yaml.Unmarshal(b, &kcc)
		if kcc.CAFile != "" || kcc.CertFile != "" {
			kcc.Insecure = false
		}
	}

	log().Info("Starting up romulusd")
	r, e := romulus.NewRegistrar(&romulus.Config{
		PeerList:            eps,
		EtcdTimeout:         *et,
		APIVersion:          *kv,
		KubeConfig:          kcc,
		Selector:            *sl,
		VulcanEtcdNamespace: *vk,
	})
	if e != nil {
		logf(fi{"err": e}).Error("Configuration Error!")
		os.Exit(2)
	}

	ctx, cancel := context.WithCancel(context.Background())
	if e := romulus.Start(r, ctx); e != nil {
		cancel()
		logf(fi{"err": e}).Fatal("Runtime Error!")
		os.Exit(1)
	}

	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT)
	select {
	case <-sig:
		l.Info("Recieved interrupt, shutting down")
		cancel()
		time.Sleep(100 * time.Millisecond)
		os.Exit(0)
	}
}
Пример #2
0
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT)
	select {
	case <-sig:
		l.Info("Recieved interrupt, shutting down")
		cancel()
		time.Sleep(100 * time.Millisecond)
		os.Exit(0)
	}
}

// F is just a simple type for adding tags to logs
type fi map[string]interface{}

var pkgField = l.Fields{"pkg": "main", "version": romulus.Version()}

// LogLevel sets the logging level
func LogLevel(lv string) {
	if lvl, e := l.ParseLevel(lv); e == nil {
		l.SetLevel(lvl)
	}
	romulus.LogLevel(lv)
}

func log() *l.Entry { return logf(nil) }
func logf(f fi) *l.Entry {
	fi := l.Fields{}
	for k, v := range pkgField {
		fi[k] = v
	}