2019-10-14 14:23:41 +00:00
|
|
|
#!/bin/bash
|
2020-01-09 15:57:07 +00:00
|
|
|
# installs and configures the desired build of Nomad as a client
|
2019-10-14 14:23:41 +00:00
|
|
|
set -o errexit
|
|
|
|
set -o nounset
|
|
|
|
|
2019-10-25 12:08:24 +00:00
|
|
|
CLOUD="$1"
|
2020-01-22 13:48:52 +00:00
|
|
|
NOMAD_CONFIG="$2"
|
2019-10-25 12:08:24 +00:00
|
|
|
|
|
|
|
# Consul
|
2019-10-28 13:27:40 +00:00
|
|
|
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
|
2019-10-25 12:08:24 +00:00
|
|
|
|
|
|
|
sudo systemctl enable consul.service
|
2020-01-16 14:29:36 +00:00
|
|
|
sudo systemctl daemon-reload
|
|
|
|
sudo systemctl restart consul.service
|
2019-10-25 12:08:24 +00:00
|
|
|
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)
|
2020-01-16 14:29:36 +00:00
|
|
|
DOCKER_BRIDGE_IP_ADDRESS=$(/usr/local/bin/sockaddr eval 'GetInterfaceIP "docker0"')
|
2019-10-25 12:08:24 +00:00
|
|
|
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
|
|
|
|
|
2019-10-28 12:21:02 +00:00
|
|
|
# Nomad
|
|
|
|
|
|
|
|
NOMAD_SRC=/ops/shared/nomad
|
|
|
|
NOMAD_DEST=/etc/nomad.d
|
2019-10-28 13:27:40 +00:00
|
|
|
NOMAD_CONFIG_FILENAME=$(basename "$NOMAD_CONFIG")
|
2019-10-28 12:21:02 +00:00
|
|
|
|
2020-01-22 13:48:52 +00:00
|
|
|
# assert Nomad binary's permissions
|
|
|
|
if [[ -f /usr/local/bin/nomad ]]; then
|
|
|
|
sudo chmod 0755 /usr/local/bin/nomad
|
|
|
|
sudo chown root:root /usr/local/bin/nomad
|
|
|
|
fi
|
2019-10-14 14:23:41 +00:00
|
|
|
|
2019-10-28 12:21:02 +00:00
|
|
|
sudo cp "$NOMAD_SRC/base.hcl" "$NOMAD_DEST/"
|
2019-10-28 13:27:40 +00:00
|
|
|
sudo cp "$NOMAD_SRC/$NOMAD_CONFIG" "$NOMAD_DEST/$NOMAD_CONFIG_FILENAME"
|
2019-10-14 14:23:41 +00:00
|
|
|
|
|
|
|
# Setup Host Volumes
|
2020-01-22 13:48:52 +00:00
|
|
|
sudo mkdir -p /tmp/data
|
2019-10-14 14:23:41 +00:00
|
|
|
|
|
|
|
# Install CNI plugins
|
|
|
|
sudo mkdir -p /opt/cni/bin
|
|
|
|
wget -q -O - \
|
2020-01-09 15:57:07 +00:00
|
|
|
https://github.com/containernetworking/plugins/releases/download/v0.8.4/cni-plugins-linux-amd64-v0.8.4.tgz \
|
2019-10-14 14:23:41 +00:00
|
|
|
| sudo tar -C /opt/cni/bin -xz
|
|
|
|
|
|
|
|
# enable as a systemd service
|
2019-10-28 12:21:02 +00:00
|
|
|
sudo cp "$NOMAD_SRC/nomad.service" /etc/systemd/system/nomad.service
|
2020-01-16 14:29:36 +00:00
|
|
|
|
2019-10-14 14:23:41 +00:00
|
|
|
sudo systemctl enable nomad.service
|
2020-01-16 14:29:36 +00:00
|
|
|
sudo systemctl daemon-reload
|
|
|
|
sudo systemctl restart nomad.service
|