예제 #1
0
파일: zkctl.go 프로젝트: chinna1986/vitess
func main() {
	defer logutil.Flush()

	flag.Parse()
	args := flag.Args()

	if len(args) == 0 {
		flag.Usage()
		os.Exit(1)
	}

	zkConfig := zkctl.MakeZkConfigFromString(*zkCfg, uint32(*myId))
	zkd := zkctl.NewZkd(zkConfig)

	action := flag.Arg(0)
	var err error
	switch action {
	case "init":
		err = zkd.Init()
	case "shutdown":
		err = zkd.Shutdown()
	case "start":
		err = zkd.Start()
	case "teardown":
		err = zkd.Teardown()
	default:
		log.Fatalf("invalid action: %v", action)
	}
	if err != nil {
		log.Fatalf("failed %v: %v", action, err)
	}
}
예제 #2
0
파일: zkctld.go 프로젝트: CowLeo/vitess
func main() {
	defer exit.Recover()
	defer logutil.Flush()

	flag.Parse()

	zkConfig := zkctl.MakeZkConfigFromString(*zkCfg, uint32(*myId))
	zkd := zkctl.NewZkd(zkConfig)

	if zkd.Inited() {
		log.Infof("already initialized, starting without init...")
		if err := zkd.Start(); err != nil {
			log.Errorf("failed start: %v", err)
			exit.Return(255)
		}
	} else {
		log.Infof("initializing...")
		if err := zkd.Init(); err != nil {
			log.Errorf("failed init: %v", err)
			exit.Return(255)
		}
	}

	log.Infof("waiting for signal or server shutdown...")
	sig := make(chan os.Signal)
	signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
	select {
	case <-zkd.Done():
		log.Infof("server shut down on its own")
	case <-sig:
		log.Infof("signal received, shutting down server")
		zkd.Shutdown()
	}
}
예제 #3
0
파일: zkctl.go 프로젝트: nangong92t/go_src
func main() {
	defer logutil.Flush()

	flag.Parse()
	args := flag.Args()

	if len(args) == 0 {
		flag.Usage()
		os.Exit(1)
	}

	zkConfig := zkctl.MakeZkConfigFromString(*zkCfg, uint32(*myId))
	zkd := zkctl.NewZkd(zkConfig)

	action := flag.Arg(0)
	var err error
	var waitForSignal bool
	switch action {
	case "init":
		err = zkd.Init()
		waitForSignal = *follow
	case "shutdown":
		err = zkd.Shutdown()
	case "start":
		err = zkd.Start()
		waitForSignal = *follow
	case "teardown":
		err = zkd.Teardown()
	default:
		log.Fatalf("invalid action: %v", action)
	}
	if err != nil {
		log.Fatalf("failed %v: %v", action, err)
	}

	if waitForSignal {
		log.Infof("waiting for signal or server shutdown...")
		sig := make(chan os.Signal)
		signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
		select {
		case <-zkd.Done():
			log.Infof("server shut down on its own")
		case <-sig:
			log.Infof("signal received, shutting down server")
			zkd.Shutdown()
		}
	}
}