func (r *EtcdMigrateServer) Start(version *EtcdVersion) error {
	etcdCmd := exec.Command(
		fmt.Sprintf("%s/etcd-%s", r.cfg.binPath, version),
		"--name", r.cfg.name,
		"--initial-cluster", r.cfg.initialCluster,
		"--debug",
		"--data-dir", r.cfg.dataDirectory,
		"--listen-client-urls", fmt.Sprintf("http://127.0.0.1:%d", r.cfg.port),
		"--advertise-client-urls", fmt.Sprintf("http://127.0.0.1:%d", r.cfg.port),
		"--listen-peer-urls", r.cfg.peerListenUrls,
		"--initial-advertise-peer-urls", r.cfg.peerAdvertiseUrls,
	)
	if r.cfg.etcdServerArgs != "" {
		extraArgs := strings.Fields(r.cfg.etcdServerArgs)
		etcdCmd.Args = append(etcdCmd.Args, extraArgs...)
	}
	fmt.Printf("Starting server %s: %+v\n", r.cfg.name, etcdCmd.Args)

	etcdCmd.Stdout = os.Stdout
	etcdCmd.Stderr = os.Stderr
	err := etcdCmd.Start()
	if err != nil {
		return err
	}
	interval := time.NewTicker(time.Millisecond * 500)
	defer interval.Stop()
	done := make(chan bool)
	go func() {
		time.Sleep(time.Minute * 2)
		done <- true
	}()
	for {
		select {
		case <-interval.C:
			err := r.client.SetEtcdVersionKeyValue(version)
			if err != nil {
				klog.Infof("Still waiting for etcd to start, current error: %v", err)
				// keep waiting
			} else {
				klog.Infof("Etcd on port %d is up.", r.cfg.port)
				r.cmd = etcdCmd
				return nil
			}
		case <-done:
			err = etcdCmd.Process.Kill()
			if err != nil {
				return fmt.Errorf("error killing etcd: %v", err)
			}
			return fmt.Errorf("timed out waiting for etcd on port %d", r.cfg.port)
		}
	}
}
// Start starts an etcd server as a separate process, waits until it has started, and returns a exec.Cmd.
Start starts an etcd server as a separate process, waits until it has started, and returns a exec.Cmd.
// Start starts an etcd server as a separate process waits until it has started and returns a exec . Cmd .
func (r *EtcdMigrateServer) Start(version *EtcdVersion) error {
	etcdCmd := exec.Command(
		fmt.Sprintf("%s/etcd-%s", r.cfg.binPath, version),
		"--name", r.cfg.name,
		"--initial-cluster", r.cfg.initialCluster,
		"--debug",
		"--data-dir", r.cfg.dataDirectory,
		"--listen-client-urls", fmt.Sprintf("http://127.0.0.1:%d", r.cfg.port),
		"--advertise-client-urls", fmt.Sprintf("http://127.0.0.1:%d", r.cfg.port),
		"--listen-peer-urls", r.cfg.peerListenUrls,
		"--initial-advertise-peer-urls", r.cfg.peerAdvertiseUrls,
	)
	if r.cfg.etcdServerArgs != "" {
		extraArgs := strings.Fields(r.cfg.etcdServerArgs)
		etcdCmd.Args = append(etcdCmd.Args, extraArgs...)
	}
	fmt.Printf("Starting server %s: %+v\n", r.cfg.name, etcdCmd.Args)
	etcdCmd.Stdout = os.Stdout
	etcdCmd.Stderr = os.Stderr
	err := etcdCmd.Start()
	if err != nil {
		return err
	}
	interval := time.NewTicker(time.Millisecond * 500)
	defer interval.Stop()
	done := make(chan bool)
	go func() {
		time.Sleep(time.Minute * 2)
		done <- true
	}()
	for {
		select {
		case <-interval.C:
			err := r.client.SetEtcdVersionKeyValue(version)
			if err != nil {
				klog.Infof("Still waiting for etcd to start, current error: %v", err)
			} else {
				klog.Infof("Etcd on port %d is up.", r.cfg.port)
				r.cmd = etcdCmd
				return nil
			}
		case <-done:
			err = etcdCmd.Process.Kill()
			if err != nil {
				return fmt.Errorf("error killing etcd: %v", err)
			}
			return fmt.Errorf("timed out waiting for etcd on port %d", r.cfg.port)
		}
	}
}
func ( r * EtcdMigrateServer ) Start ( version * EtcdVersion ) error { etcdCmd := exec . Command ( fmt . Sprintf ( " " , r . cfg . binPath , version ) , " " , r . cfg . name , " " , r . cfg . initialCluster , " " , " " , r . cfg . dataDirectory , " " , fmt . Sprintf ( " " , r . cfg . port ) , " " , fmt . Sprintf ( " " , r . cfg . port ) , " " , r . cfg . peerListenUrls , " " , r . cfg . peerAdvertiseUrls , ) if r . cfg . etcdServerArgs != " " { extraArgs := strings . Fields ( r . cfg . etcdServerArgs ) etcdCmd . Args = append ( etcdCmd . Args , extraArgs ... ) } fmt . Printf ( " \n " , r . cfg . name , etcdCmd . Args ) etcdCmd . Stdout = os . Stdout etcdCmd . Stderr = os . Stderr err := etcdCmd . Start ( ) if err != nil { return err } interval := time . NewTicker ( time . Millisecond * 500 ) defer interval . Stop ( ) done := make ( chan bool ) go func ( ) { time . Sleep ( time . Minute * 2 ) done <- true } ( ) for { select { case <- interval . C : err := r . client . SetEtcdVersionKeyValue ( version ) if err != nil { klog . Infof ( " " , err ) } else { klog . Infof ( " " , r . cfg . port ) r . cmd = etcdCmd return nil } case <- done : err = etcdCmd . Process . Kill ( ) if err != nil { return fmt . Errorf ( " " , err ) } return fmt . Errorf ( " " , r . cfg . port ) } } }
Start starts an etcd server as a separate process, waits until it has started, and returns a exec.Cmd.
Start starts an etcd server as a separate process waits until it has started and returns a exec . Cmd .
// keep waiting