#!/bin/bash # installs and configures the desired build of Nomad as a server set -o errexit set -o nounset CONFIGDIR=/ops/shared/config HADOOP_VERSION=hadoop-2.7.7 HADOOPCONFIGDIR=/usr/local/$HADOOP_VERSION/etc/hadoop HOME_DIR=ubuntu IP_ADDRESS=$(/usr/local/bin/sockaddr eval 'GetPrivateIP') DOCKER_BRIDGE_IP_ADDRESS=$(/usr/local/bin/sockaddr eval 'GetInterfaceIP "docker0"') CLOUD="$1" NOMAD_SHA="$2" NOMAD_CONFIG="$3" # Consul CONSUL_SRC=/ops/shared/consul CONSUL_DEST=/etc/consul.d sudo cp "$CONSUL_SRC/base.json" "$CONSUL_DEST/" sudo cp "$CONSUL_SRC/retry_$CLOUD.json" "$CONSUL_DEST/" sudo cp "$CONSUL_SRC/consul_$CLOUD.service" /etc/systemd/system/consul.service sudo systemctl enable consul.service sudo systemctl start consul.service sleep 10 # Add hostname to /etc/hosts echo "127.0.0.1 $(hostname)" | sudo tee --append /etc/hosts # Add Docker bridge network IP to /etc/resolv.conf (at the top) echo "nameserver $DOCKER_BRIDGE_IP_ADDRESS" | sudo tee /etc/resolv.conf.new cat /etc/resolv.conf | sudo tee --append /etc/resolv.conf.new sudo mv /etc/resolv.conf.new /etc/resolv.conf # Hadoop config file to enable HDFS CLI sudo cp $CONFIGDIR/core-site.xml $HADOOPCONFIGDIR # Move examples directory to $HOME sudo mv /ops/examples /home/$HOME_DIR sudo chown -R $HOME_DIR:$HOME_DIR /home/$HOME_DIR/examples sudo chmod -R 775 /home/$HOME_DIR/examples # Set env vars for tool CLIs echo "export NOMAD_ADDR=http://$IP_ADDRESS:4646" | sudo tee --append /home/$HOME_DIR/.bashrc echo "export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre" | sudo tee --append /home/$HOME_DIR/.bashrc # Update PATH echo "export PATH=$PATH:/usr/local/bin/spark/bin:/usr/local/$HADOOP_VERSION/bin" | sudo tee --append /home/$HOME_DIR/.bashrc # Nomad NOMAD_SRC=/ops/shared/nomad NOMAD_DEST=/etc/nomad.d NOMAD_CONFIG_FILENAME=$(basename "$NOMAD_CONFIG") # download aws s3 cp "s3://nomad-team-test-binary/builds-oss/nomad_linux_amd64_${NOMAD_SHA}.tar.gz" nomad.tar.gz # unpack and install sudo tar -zxvf nomad.tar.gz -C /usr/local/bin/ sudo chmod 0755 /usr/local/bin/nomad sudo chown root:root /usr/local/bin/nomad sudo cp "$NOMAD_SRC/base.hcl" "$NOMAD_DEST/" sudo cp "$NOMAD_SRC/$NOMAD_CONFIG" "$NOMAD_DEST/$NOMAD_CONFIG_FILENAME" # Setup Host Volumes sudo mkdir /tmp/data # Install CNI plugins sudo mkdir -p /opt/cni/bin wget -q -O - \ https://github.com/containernetworking/plugins/releases/download/v0.8.2/cni-plugins-linux-amd64-v0.8.2.tgz \ | sudo tar -C /opt/cni/bin -xz # enable as a systemd service sudo cp "$NOMAD_SRC/nomad.service" /etc/systemd/system/nomad.service sudo systemctl enable nomad.service sudo systemctl start nomad.service