Example #1
0
func (d *Deter) Deploy() error {
	dbg.Lvl1("Assembling all files and configuration options")
	os.RemoveAll(d.DeployDir)
	os.Mkdir(d.DeployDir, 0777)

	dbg.Lvl1("Writing config-files")

	d.generateHostsFile()
	d.readHosts()
	d.calculateGraph()
	d.WriteConfig()

	// copy the webfile-directory of the logserver to the remote directory
	err := exec.Command("cp", "-a", d.DeterDir+"/logserver/webfiles",
		d.DeterDir+"/cothority.conf", d.DeployDir).Run()
	if err != nil {
		log.Fatal("error copying webfiles:", err)
	}
	build, err := ioutil.ReadDir(d.BuildDir)
	for _, file := range build {
		err = exec.Command("cp", d.BuildDir+"/"+file.Name(), d.DeployDir).Run()
		if err != nil {
			log.Fatal("error copying build-file:", err)
		}
	}

	dbg.Lvl1("Copying over to", d.Login, "@", d.Host)
	// Copy everything over to deterlabs
	err = cliutils.Rsync(d.Login, d.Host, d.DeployDir+"/", "remote/")
	if err != nil {
		log.Fatal(err)
	}

	dbg.Lvl1("Done copying")

	dbg.Lvl3(cliutils.SshRunStdout(d.Login, d.Host,
		""))

	return nil
}
Example #2
0
// Creates the appropriate configuration-files and copies everything to the
// deterlab-installation.
func (d *Deterlab) Deploy(rc RunConfig) error {
	dbg.Lvlf1("Next run is %+v", rc)
	os.RemoveAll(d.DeployDir)
	os.Mkdir(d.DeployDir, 0777)

	dbg.Lvl3("Writing config-files")

	// Initialize the deter-struct with our current structure (for debug-levels
	// and such), then read in the app-configuration to overwrite eventual
	// 'Machines', 'ppm', '' or other fields
	deter := *d
	appConfig := d.DeployDir + "/app.toml"
	deterConfig := d.DeployDir + "/deter.toml"
	ioutil.WriteFile(appConfig, rc.Toml(), 0666)
	deter.ReadConfig(appConfig)

	deter.createHosts()
	d.MasterLogger = deter.MasterLogger
	app.WriteTomlConfig(deter, deterConfig)

	// Prepare special configuration preparation for each application - the
	// reading in twice of the configuration file, once for the deterConfig,
	// then for the appConfig, sets the deterConfig as defaults and overwrites
	// everything else with the actual appConfig (which comes from the
	// runconfig-file)
	switch d.App {
	case "sign", "stamp":
		conf := app.ConfigColl{}
		conf.StampsPerRound = -1
		conf.StampRatio = 1.0
		app.ReadTomlConfig(&conf, deterConfig)
		app.ReadTomlConfig(&conf, appConfig)
		// Calculates a tree that is used for the timestampers
		var depth int
		conf.Tree, conf.Hosts, depth, _ = graphs.TreeFromList(deter.Virt[:], conf.Ppm, conf.Bf)
		dbg.Lvl2("Depth:", depth)
		dbg.Lvl2("Total peers:", len(conf.Hosts))
		total := deter.Machines * conf.Ppm
		if len(conf.Hosts) != total {
			dbg.Fatal("Only calculated", len(conf.Hosts), "out of", total, "hosts - try changing number of",
				"machines or hosts per node")
		}
		deter.Hostnames = conf.Hosts
		// re-write the new configuration-file
		app.WriteTomlConfig(conf, appConfig)
	case "skeleton":
		conf := app.ConfigSkeleton{}
		app.ReadTomlConfig(&conf, deterConfig)
		app.ReadTomlConfig(&conf, appConfig)
		// Calculates a tree that is used for the timestampers
		var depth int
		conf.Tree, conf.Hosts, depth, _ = graphs.TreeFromList(deter.Virt[:], conf.Ppm, conf.Bf)
		dbg.Lvl2("Depth:", depth)
		dbg.Lvl2("Total peers:", len(conf.Hosts))
		total := deter.Machines * conf.Ppm
		if len(conf.Hosts) != total {
			dbg.Fatal("Only calculated", len(conf.Hosts), "out of", total, "hosts - try changing number of",
				"machines or hosts per node")
		}
		deter.Hostnames = conf.Hosts
		// re-write the new configuration-file
		app.WriteTomlConfig(conf, appConfig)

	case "shamir":
		conf := app.ConfigShamir{}
		app.ReadTomlConfig(&conf, deterConfig)
		app.ReadTomlConfig(&conf, appConfig)
		_, conf.Hosts, _, _ = graphs.TreeFromList(deter.Virt[:], conf.Ppm, conf.Ppm)
		deter.Hostnames = conf.Hosts
		// re-write the new configuration-file
		app.WriteTomlConfig(conf, appConfig)
	case "naive":
		conf := app.NaiveConfig{}
		app.ReadTomlConfig(&conf, deterConfig)
		app.ReadTomlConfig(&conf, appConfig)
		_, conf.Hosts, _, _ = graphs.TreeFromList(deter.Virt[:], conf.Ppm, 2)
		deter.Hostnames = conf.Hosts
		dbg.Lvl3("Deterlab: naive applications:", conf.Hosts)
		dbg.Lvl3("Deterlab: naive app config:", conf)
		dbg.Lvl3("Deterlab: naive app virt:", deter.Virt[:])
		deter.Hostnames = conf.Hosts
		app.WriteTomlConfig(conf, appConfig)
	case "ntree":
		conf := app.NTreeConfig{}
		app.ReadTomlConfig(&conf, deterConfig)
		app.ReadTomlConfig(&conf, appConfig)
		var depth int
		conf.Tree, conf.Hosts, depth, _ = graphs.TreeFromList(deter.Virt[:], conf.Ppm, conf.Bf)
		dbg.Lvl2("Depth:", depth)
		deter.Hostnames = conf.Hosts
		app.WriteTomlConfig(conf, appConfig)

	case "randhound":
	}
	app.WriteTomlConfig(deter, "deter.toml", d.DeployDir)

	// copy the webfile-directory of the logserver to the remote directory
	err := exec.Command("cp", "-a", d.DeterDir+"/cothority.conf", d.DeployDir).Run()
	if err != nil {
		dbg.Fatal("error copying webfiles:", err)
	}
	build, err := ioutil.ReadDir(d.BuildDir)
	for _, file := range build {
		err = exec.Command("cp", d.BuildDir+"/"+file.Name(), d.DeployDir).Run()
		if err != nil {
			dbg.Fatal("error copying build-file:", err)
		}
	}

	dbg.Lvl1("Copying over to", d.Login, "@", d.Host)
	// Copy everything over to Deterlabs
	err = cliutils.Rsync(d.Login, d.Host, d.DeployDir+"/", "remote/")
	if err != nil {
		dbg.Fatal(err)
	}
	dbg.Lvl2("Done copying")

	return nil
}