Пример #1
0
func start(isWorker bool, z *config.ZookeeperConfig, i *config.InstallConfig, s *config.SparkConfig) {
	// If this is a worker, create a lock file in its working directory
	if isWorker {
		if _, err := lockfile.Create("lock"); err != nil {
			fmt.Fprintf(os.Stderr, "Worker cannot obtain lock (%s)\n", err)
			os.Exit(1)
		}
	}

	// Connect to Zookeeper for anchor file system
	aconn := zanchorfs.Dial(z.Workers)
	anchorfs.Bind(zanchorfs.New(aconn, z.AnchorDir()))

	// Connect to Zookeeper for durable file system
	dconn := zdurablefs.Dial(z.Workers)
	durablefs.Bind(zdurablefs.New(dconn, z.DurableDir()))

	// Connect to Zookeeper for issue file system
	iconn := zissuefs.Dial(z.Workers)
	issuefs.Bind(zissuefs.New(iconn, z.IssueDir()))

	// Initialize the networking module
	worker.Bind(workerBackend.New(i.LibPath, path.Join(i.BinDir(), i.Worker), i.JailDir()))

	// Initialize transport module
	t := transport.New(s.ID, s.BindAddr, s.Host)

	// Initialize language runtime
	circuit.Bind(lang.New(t))

	// Create anchors
	for _, a := range s.Anchor {
		a = strings.TrimSpace(a)
		if err := anchorfs.CreateFile(a, t.Addr()); err != nil {
			fmt.Fprintf(os.Stderr, "Problem creating anchor '%s' (%s)\n", a, err)
			os.Exit(1)
		}
	}

	if isWorker {
		// A worker sends back its PID and runtime port to its invoker (the daemonizer)
		backpipe := os.NewFile(3, "backpipe")
		if _, err := backpipe.WriteString(strconv.Itoa(os.Getpid()) + "\n"); err != nil {
			panic(err)
		}
		if _, err := backpipe.WriteString(strconv.Itoa(t.Port()) + "\n"); err != nil {
			panic(err)
		}
		if err := backpipe.Close(); err != nil {
			panic(err)
		}
		// Hang forever is done in the auto-generated, by 4build, worker main method
	}
}
Пример #2
0
func installHost(i *config.InstallConfig, b *config.BuildConfig, host string) error {

	// Prepare shell script
	t := template.New("_")
	template.Must(t.Parse(installShSrc))
	var w bytes.Buffer
	if err := t.Execute(&w, &struct{ BinDir, JailDir, VarDir string }{
		BinDir:  i.BinDir(),
		JailDir: i.JailDir(),
		VarDir:  i.VarDir(),
	}); err != nil {
		return err
	}
	install_sh := string(w.Bytes())

	// Execute remotely
	if _, _, err := posix.RemoteShell(host, install_sh); err != nil {
		return err
	}
	if err := posix.UploadDir(host, b.ShipDir, i.BinDir()); err != nil {
		return err
	}
	return nil
}