コード例 #1
0
ファイル: timeclient.go プロジェクト: ineiti/prifi
func init() {
	addr, _ := oldconfig.GetAddress()
	// TODO: change to take in list of servers: comma separated no spaces
	//   -server=s1,s2,s3,...
	flag.StringVar(&server, "server", "", "the timestamping servers to contact")
	flag.IntVar(&nmsgs, "nmsgs", 100, "messages per round")
	flag.StringVar(&name, "name", addr, "name for the client")
	flag.StringVar(&logger, "logger", "", "remote logger")
	flag.IntVar(&rate, "rate", -1, "milliseconds between timestamp requests")
	flag.BoolVar(&debug, "debug", false, "set debug mode")
	//log.SetFormatter(&log.JSONFormatter{})
}
コード例 #2
0
ファイル: deploy.go プロジェクト: ineiti/prifi
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()
	zoo := true
	if mode == "pl" || mode == "planetlab" {
		zoo = false
	}
	SetupLogs()
	Done := BuildExec()
	// establish logging server to listen to remote connections
	go StartLoggingServer(":9000")
	log.Println("started logging server")
	addr, err := oldconfig.GetAddress()
	if err != nil {
		addr = ""
	}

	log.Println("parsing hosts")
	logserver := addr + ":9000"
	if addr != "" {
		logserver = ""
	}
	log.Print(logserver)

	// parse out the hostnames
	var hostnames []string
	if hostList != "" {
		temp := strings.Split(hostList, ",")
		for i := range temp {
			temp[i] = strings.TrimSpace(temp[i])
			if temp[i] != "" {
				hostnames = append(hostnames, temp[i])
			}
		}
	}
	log.Println("hosts: ", hostnames)

	// update the config to represent a tcp configuration with the given hostnames
	b, err := ioutil.ReadFile(configFile)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("REWRITING PORT:", portRewrite)
	hc, err := oldconfig.LoadJSON(b, oldconfig.ConfigOptions{ConnType: "tcp", Hostnames: hostnames, Port: portRewrite})
	if err != nil {
		log.Fatal("bad config file:", err)
	}
	f, err := ioutil.TempFile("./", "config")
	if err != nil {
		log.Fatal(err)
	}
	err = ioutil.WriteFile(f.Name(), []byte(hc.String()), 0666)
	if err != nil {
		log.Fatal(err)
	}

	// get the definative list of hostnames
	hostnames = make([]string, 0, len(hc.Hosts))
	for h := range hc.Hosts {
		hostnames = append(hostnames, h)
	}

	log.Println("final hostnames: ", hostnames)

	log.Println("sending configuration file")
	// send this file to the hosts (using proper authentication)
	var wg sync.WaitGroup
	// if clean == "true" {
	// 	for _, host := range hostnames {
	// 		wg.Add(1)
	// 		go func(host string) {
	// 			defer wg.Done()
	// 			h := strings.Split(host, ":")[0]
	// 			if username != "" {
	// 				h = username + "@" + h
	// 			}
	// 			cmd := exec.Command("ssh", h,
	// 				"rm config*")
	// 			log.Println(cmd.Args)
	// 			cmd.Stdout = LogWriter
	// 			cmd.Stderr = LogWriter
	// 			err := cmd.Run()
	// 			if err != nil {
	// 				log.Println(h, err)
	// 			}
	// 		}(host)
	// 	}
	// 	wg.Wait()
	// }
	log.Println("waiting for done: ", Done)
	<-Done
	log.Println("done")
	for _, host := range hostnames {
		wg.Add(1)
		go func(host string) {
			defer wg.Done()
			h := strings.Split(host, ":")[0]
			if username != "" {
				h = username + "@" + h
			}
			log.Println("starting scp: ", h)
			cmd := exec.Command("scp", "-C", "-B", f.Name(), h+":"+f.Name())
			cmd.Stdout = LogWriter
			cmd.Stderr = LogWriter
			err := cmd.Run()
			if err != nil {
				log.Fatal("scp failed on: ", h, err)
			}
		}(host)
		// only need to send one file to the zoo
		if zoo {
			break
		}
	}
	wg.Wait()
	log.Println("waiting for build to finish")
	// <-buildDone
	log.Println("sending executable")

	// scp that file to the hosts
	// send this file to the hosts (using proper authentication)
	for _, host := range hostnames {
		wg.Add(1)
		go func(host string) {
			defer wg.Done()
			h := strings.Split(host, ":")[0]
			if username != "" {
				h = username + "@" + h
			}
			cmd := exec.Command("scp", "-C", "exec", h+":"+"cocoexec")
			cmd.Stdout = LogWriter
			cmd.Stderr = LogWriter
			log.Println("scp binary to ", h)
			err := cmd.Run()
			if err != nil {
				log.Fatal(h, ": scp:", err)
			}
			err = exec.Command("ssh", h,
				"eval 'chmod +x cocoexec'").Run()
			if err != nil {
				log.Print(h, ": chmod:", err)
			}
		}(host)
		if zoo {
			break
		}
	}
	wg.Wait()

	// ssh run the file on each of the hosts
	for _, host := range hostnames {
		wg.Add(1)
		go func(host string) {
			defer wg.Done()
			h := strings.Split(host, ":")[0]
			if username != "" {
				h = username + "@" + h
			}
			cmd := exec.Command("ssh", h,
				"eval './cocoexec -hostname "+host+" -config "+f.Name()+" -logger "+logserver+"'")
			log.Println(cmd.Args)
			cmd.Stdout = LogWriter
			cmd.Stderr = LogWriter
			err := cmd.Run()
			if err != nil {
				log.Println(h, err)
			}
		}(host)
	}
	wg.Wait()
	fmt.Println("All children have completed")
}