Example #1
0
func main() {
	cfgPath := flag.String("config_file", "", "Path to config file.")
	flag.Parse()

	cfg, err := loadConfigFromPath(*cfgPath)
	if err != nil {
		glog.Errorf(err.Error())
		syscall.Exit(1)
	}

	if cfg.Verbosity >= 2 {
		etcd.OpenDebug()
	}

	srv := server.New(*cfg)
	srv.Run()

	reconfigure := func() {
		glog.Infof("Reloading config file from %s", *cfgPath)
		cfg, err := loadConfigFromPath(*cfgPath)
		if err != nil {
			glog.Errorf(err.Error())
			syscall.Exit(1)
		} else {
			srv.Configure(cfg)
		}
	}

	listenForSignal(syscall.SIGHUP, reconfigure)
}
Example #2
0
func main() {
	// We use a custom FlagSet since golang/glog adds a bunch of flags we
	// do not want to publish
	flagset := flag.NewFlagSet("coreinit", flag.ExitOnError)
	cfgPath := flagset.String("config_file", "", "Path to config file.")
	err := flagset.Parse(os.Args[1:])

	// We do this manually since we're using a custom FlagSet
	if err == flag.ErrHelp {
		flag.Usage()
		syscall.Exit(1)
	}

	// Print out to stderr by default (stderr instead of stdout due to glog's choices)
	flag.Lookup("logtostderr").Value.Set("true")

	cfg, err := loadConfigFromPath(*cfgPath)
	if err != nil {
		glog.Errorf(err.Error())
		syscall.Exit(1)
	}

	if cfg.Verbosity >= 3 {
		etcd.OpenDebug()
	}

	srv := server.New(*cfg)
	srv.Run()

	reconfigure := func() {
		glog.Infof("Reloading config file from %s", *cfgPath)
		cfg, err := loadConfigFromPath(*cfgPath)
		if err != nil {
			glog.Errorf(err.Error())
			syscall.Exit(1)
		} else {
			srv.Configure(cfg)
		}
	}

	listenForSignal(syscall.SIGHUP, reconfigure)
}