github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/roachprod/install/install.go (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package install
    12  
    13  import (
    14  	"bytes"
    15  	"fmt"
    16  	"sort"
    17  )
    18  
    19  // Clusters memoizes cluster info for install operations
    20  var Clusters = map[string]*SyncedCluster{}
    21  
    22  var installCmds = map[string]string{
    23  	"cassandra": `
    24  echo "deb http://www.apache.org/dist/cassandra/debian 311x main" | \
    25  	sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list;
    26  curl https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -;
    27  sudo apt-get update;
    28  sudo apt-get install -y cassandra;
    29  sudo service cassandra stop;
    30  `,
    31  
    32  	"charybdefs": `
    33    thrift_dir="/opt/thrift"
    34  
    35    if [ ! -f "/usr/bin/thrift" ]; then
    36  	sudo apt-get update;
    37  	sudo apt-get install -qy automake bison flex g++ git libboost-all-dev libevent-dev libssl-dev libtool make pkg-config python-setuptools libglib2.0-dev
    38  
    39      sudo mkdir -p "${thrift_dir}"
    40      sudo chmod 777 "${thrift_dir}"
    41      cd "${thrift_dir}"
    42      curl "https://downloads.apache.org/thrift/0.10.0/thrift-0.10.0.tar.gz" | sudo tar xvz --strip-components 1
    43      sudo ./configure --prefix=/usr
    44      sudo make -j$(nproc)
    45      sudo make install
    46      (cd "${thrift_dir}/lib/py" && sudo python setup.py install)
    47    fi
    48  
    49    charybde_dir="/opt/charybdefs"
    50    nemesis_path="${charybde_dir}/charybdefs-nemesis"
    51  
    52    if [ ! -f "${nemesis_path}" ]; then
    53      sudo apt-get install -qy build-essential cmake libfuse-dev fuse
    54      sudo rm -rf "${charybde_dir}" "${nemesis_path}" /usr/local/bin/charybdefs{,-nemesis}
    55      sudo mkdir -p "${charybde_dir}"
    56      sudo chmod 777 "${charybde_dir}"
    57      git clone --depth 1 "https://github.com/scylladb/charybdefs.git" "${charybde_dir}"
    58  
    59      cd "${charybde_dir}"
    60      thrift -r --gen cpp server.thrift
    61      cmake CMakeLists.txt
    62      make -j$(nproc)
    63  
    64      sudo modprobe fuse
    65      sudo ln -s "${charybde_dir}/charybdefs" /usr/local/bin/charybdefs
    66      cat > "${nemesis_path}" <<EOF
    67  #!/bin/bash
    68  cd /opt/charybdefs/cookbook
    69  ./recipes "\$@"
    70  EOF
    71      chmod +x "${nemesis_path}"
    72  	sudo ln -s "${nemesis_path}" /usr/local/bin/charybdefs-nemesis
    73  fi
    74  `,
    75  
    76  	"confluent": `
    77  sudo apt-get update;
    78  sudo apt-get install -y default-jdk-headless;
    79  curl https://packages.confluent.io/archive/5.0/confluent-oss-5.0.0-2.11.tar.gz | sudo tar -C /usr/local -xz;
    80  sudo ln -s /usr/local/confluent-5.0.0 /usr/local/confluent;
    81  `,
    82  
    83  	"docker": `
    84  sudo apt-get update;
    85  sudo apt-get install  -y \
    86      apt-transport-https \
    87      ca-certificates \
    88      curl \
    89      software-properties-common;
    90  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -;
    91  sudo add-apt-repository \
    92     "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    93     $(lsb_release -cs) \
    94     stable";
    95  
    96  sudo apt-get update;
    97  sudo apt-get install  -y docker-ce;
    98  `,
    99  
   100  	"gcc": `
   101  sudo apt-get update;
   102  sudo apt-get install -y gcc;
   103  `,
   104  
   105  	// graphviz and rlwrap are useful for pprof
   106  	"go": `
   107  sudo apt-get update;
   108  sudo apt-get install -y graphviz rlwrap;
   109  
   110  curl https://dl.google.com/go/go1.12.linux-amd64.tar.gz | sudo tar -C /usr/local -xz;
   111  echo 'export PATH=$PATH:/usr/local/go/bin' | sudo tee /etc/profile.d/go.sh > /dev/null;
   112  sudo chmod +x /etc/profile.d/go.sh;
   113  `,
   114  
   115  	"haproxy": `
   116  sudo apt-get update;
   117  sudo apt-get install -y haproxy;
   118  `,
   119  
   120  	"ntp": `
   121  sudo apt-get update;
   122  sudo apt-get install -y \
   123    ntp \
   124    ntpdate;
   125  `,
   126  
   127  	"sysbench": `
   128  curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bash;
   129  sudo apt-get update;
   130  sudo apt-get install -y sysbench;
   131  `,
   132  
   133  	"tools": `
   134  sudo apt-get update;
   135  sudo apt-get install -y \
   136    fio \
   137    iftop \
   138    iotop \
   139    sysstat \
   140    linux-tools-common \
   141    linux-tools-4.10.0-35-generic \
   142    linux-cloud-tools-4.10.0-35-generic;
   143  `,
   144  
   145  	"zfs": `
   146  sudo apt-get update;
   147  sudo apt-get install -y \
   148    zfsutils-linux;
   149  `,
   150  }
   151  
   152  // SortedCmds TODO(peter): document
   153  func SortedCmds() []string {
   154  	cmds := make([]string, 0, len(installCmds))
   155  	for cmd := range installCmds {
   156  		cmds = append(cmds, cmd)
   157  	}
   158  	sort.Strings(cmds)
   159  	return cmds
   160  }
   161  
   162  // Install TODO(peter): document
   163  func Install(c *SyncedCluster, args []string) error {
   164  	do := func(title, cmd string) error {
   165  		var buf bytes.Buffer
   166  		err := c.Run(&buf, &buf, c.Nodes, OtherCmd, "installing "+title, cmd)
   167  		if err != nil {
   168  			fmt.Print(buf.String())
   169  		}
   170  		return err
   171  	}
   172  
   173  	for _, arg := range args {
   174  		cmd, ok := installCmds[arg]
   175  		if !ok {
   176  			return fmt.Errorf("unknown tool %q", arg)
   177  		}
   178  
   179  		// Ensure that we early exit if any of the shell statements fail.
   180  		cmd = "set -exuo pipefail;" + cmd
   181  		if err := do(arg, cmd); err != nil {
   182  			return err
   183  		}
   184  	}
   185  	return nil
   186  }