コード例 #1
0
// RunDockerStart starts the cockroach binary.
func RunDockerStart(driver drivers.Driver, nodeName string, settings *drivers.HostConfig) error {
	dockerArgs, err := GetDockerFlags(nodeName)
	if err != nil {
		return err
	}
	port := driver.Context().Port
	args := dockerArgs
	args = append(args,
		"run",
		"-d",
		"-v", fmt.Sprintf("%s:/data", settings.Driver.DataDir()),
		"-p", fmt.Sprintf("%d:%d", port, port),
		"--net", "host",
		"cockroachdb/cockroach",
		"start",
		"--insecure",
		"--stores=ssd=/data",
		// --addr must be an address reachable by other nodes.
		fmt.Sprintf("--addr=%s:%d", settings.Driver.IPAddress(), port),
		// TODO(marc): remove localhost once we serve /_status/ before
		// joining the gossip network.
		fmt.Sprintf("--gossip=localhost:%d,http-lb=%s:%d", port, settings.Driver.GossipAddress(), port),
	)
	log.Infof("running: docker %s", strings.Join(args, " "))
	cmd := exec.Command("docker", args...)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	return cmd.Run()
}
コード例 #2
0
// CreateMachine creates a new docker machine using the passed-in driver
// and name.
func CreateMachine(driver drivers.Driver, name string) error {
	log.Infof("creating docker-machine %s", name)

	args := []string{
		"create",
		"--driver", driver.DockerMachineDriver(),
	}
	args = append(args, driver.DockerMachineCreateArgs()...)
	args = append(args, name)

	log.Infof("running: %s %s", dockerMachineBinary, strings.Join(args, " "))
	cmd := exec.Command(dockerMachineBinary, args...)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	return cmd.Run()
}
コード例 #3
0
ファイル: add_nodes.go プロジェクト: bdarnell/cockroach-prod
// AddOneNode is a helper to add a single node. Called repeatedly.
func AddOneNode(driver drivers.Driver) error {
	nodes, err := docker.ListCockroachNodes()
	if err != nil {
		return util.Errorf("failed to get list of existing cockroach nodes: %v", err)
	}
	if len(nodes) == 0 {
		return util.Errorf("no existing cockroach nodes detected, does the cluster exist?")
	}

	largestIndex, err := docker.GetLargestNodeIndex(nodes)
	if err != nil {
		return util.Errorf("problem parsing existing node list: %v", err)
	}

	nodeName := docker.MakeNodeName(largestIndex + 1)

	// Create node.
	err = docker.CreateMachine(driver, nodeName)
	if err != nil {
		return util.Errorf("could not create machine %s: %v", nodeName, err)
	}

	// Lookup node info.
	nodeConfig, err := driver.GetNodeConfig(nodeName)
	if err != nil {
		return util.Errorf("could not get node config for %s: %v", nodeName, err)
	}

	// Do "start node" logic.
	err = driver.StartNode(nodeName, nodeConfig)
	if err != nil {
		return util.Errorf("could not run StartNode steps for %s: %v", nodeName, err)
	}

	// Start the cockroach node.
	err = docker.RunDockerStart(driver, nodeName, nodeConfig)
	if err != nil {
		return util.Errorf("could not initialize first cockroach node %s: %v", nodeName, err)
	}
	return nil
}
コード例 #4
0
ファイル: cli.go プロジェクト: nvanbenschoten/cockroach-prod
// NewDriver creates a new driver based on the passed-in Context
// and initializes it.
// This sets up authentication and should be called before
// driver-specific docker-machine commands.
func NewDriver(context *base.Context) (drivers.Driver, error) {
	tokens := strings.SplitN(context.Region, ":", 2)
	if len(tokens) != 2 {
		return nil, util.Errorf("invalid region syntax, expected <driver>:<region name>, got: %q", context.Region)
	}

	var driver drivers.Driver

	provider := tokens[0]
	region := tokens[1]
	switch provider {
	case "aws":
		driver = amazon.NewDriver(context, region)
	case "gce":
		driver = google.NewDriver(context, region)
	default:
		return nil, util.Errorf("unknown driver: %s", driver)
	}

	err := driver.Init()
	return driver, err
}