Skip to content

Instantly share code, notes, and snippets.

@jonasrosland
Last active August 24, 2016 13:37
Show Gist options
  • Select an option

  • Save jonasrosland/c8a860100161051ec54dbc8e1f0f4220 to your computer and use it in GitHub Desktop.

Select an option

Save jonasrosland/c8a860100161051ec54dbc8e1f0f4220 to your computer and use it in GitHub Desktop.
sudo useradd consul
sudo mkdir -p /etc/consul.d/{bootstrap,server,client}
sudo mkdir /var/consul
sudo chown consul:consul /var/consul
wget -nc -nv https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip 1&>2
unzip -o consul_0.6.4_linux_amd64.zip
sudo cp consul /usr/local/bin
if [ "$HOSTNAME" = mesos-master ]; then
echo "on master"
sudo tee /etc/consul.d/bootstrap/config.json >/dev/null << EOF
{
"bootstrap": true,
"advertise_addr": "10.141.141.10",
"client_addr": "0.0.0.0",
"server": true,
"datacenter": "nyc2",
"data_dir": "/var/consul",
"encrypt": "X4SYOinf2pTAcAHRhpj7dA==",
"log_level": "INFO",
"enable_syslog": true
}
EOF
sudo tee /etc/consul.d/server/config.json >/dev/null << EOF
{
"bootstrap": false,
"advertise_addr": "10.141.141.10",
"client_addr": "0.0.0.0",
"server": true,
"datacenter": "nyc2",
"data_dir": "/var/consul",
"encrypt": "X4SYOinf2pTAcAHRhpj7dA==",
"log_level": "INFO",
"enable_syslog": true,
"ui": true,
"start_join": ["10.141.141.11", "10.141.141.12"]
}
EOF
sudo tee /etc/init/consul-bootstrap.conf >/dev/null << EOF
description "Consul server process"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
respawn
setuid consul
setgid consul
exec consul agent -ui -config-dir /etc/consul.d/bootstrap
EOF
sudo service consul-bootstrap start
# add our public key to apt
curl -s https://bintray.com/user/downloadSubjectPublicKey?username=allegro | sudo apt-key add -
# add the repository url
echo "deb http://dl.bintray.com/v1/content/allegro/deb /" | sudo tee /etc/apt/sources.list.d/marathon-consul.list
# update apt cache
sudo apt-get -y update
# install latest release of marathon-consul
sudo apt-get -qy install marathon-consul
sudo service marathon-consul start
sudo tee /etc/init/marathon.conf >/dev/null << EOF
description "Marathon scheduler for Mesos"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
exec /usr/bin/marathon --event_subscriber http_callback
EOF
sudo service marathon restart
sleep 20
curl -s -X POST 'http://localhost:8080/v2/eventSubscriptions?callbackUrl=http://localhost:4000/events'
fi
if [ "$HOSTNAME" = mesos-slave1 ]; then
printf "on slave1"
sudo tee /etc/consul.d/server/config.json >/dev/null << EOF
{
"bootstrap": false,
"advertise_addr": "10.141.141.11",
"client_addr": "0.0.0.0",
"server": true,
"datacenter": "nyc2",
"data_dir": "/var/consul",
"encrypt": "X4SYOinf2pTAcAHRhpj7dA==",
"log_level": "INFO",
"enable_syslog": true,
"start_join": ["10.141.141.10", "10.141.141.12"]
}
EOF
sudo tee /etc/init/consul.conf >/dev/null << EOF
description "Consul server process"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
respawn
setuid consul
setgid consul
exec consul agent -config-dir /etc/consul.d/server
EOF
sudo service consul start
else
echo "not on slave1"
fi
if [ "$HOSTNAME" = mesos-slave2 ]; then
printf "on slave2"
sudo tee /etc/consul.d/server/config.json >/dev/null << EOF
{
"bootstrap": false,
"advertise_addr": "10.141.141.12",
"client_addr": "0.0.0.0",
"server": true,
"datacenter": "nyc2",
"data_dir": "/var/consul",
"encrypt": "X4SYOinf2pTAcAHRhpj7dA==",
"log_level": "INFO",
"enable_syslog": true,
"start_join": ["10.141.141.10", "10.141.141.11"]
}
EOF
sudo tee /etc/init/consul.conf >/dev/null << EOF
description "Consul server process"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
respawn
setuid consul
setgid consul
exec consul agent -config-dir /etc/consul.d/server
EOF
sudo service consul start
else
echo "not on slave2"
fi
if [ "$HOSTNAME" = mesos-slave3 ]; then
printf "on slave3"
sudo tee /etc/consul.d/client/config.json >/dev/null << EOF
{
"client_addr": "0.0.0.0",
"advertise_addr": "10.141.141.13",
"datacenter": "nyc2",
"data_dir": "/var/consul",
"encrypt": "X4SYOinf2pTAcAHRhpj7dA==",
"log_level": "INFO",
"enable_syslog": true,
"start_join": ["10.141.141.10", "10.141.141.11", "10.141.141.12"]
}
EOF
sudo tee /etc/init/consul.conf >/dev/null << EOF
description "Consul server process"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
respawn
setuid consul
setgid consul
exec consul agent -config-dir /etc/consul.d/client
EOF
sudo service consul start
else
echo "not on slave3"
fi
if [ "$HOSTNAME" = mesos-slave4 ]; then
printf "on slave4"
sudo tee /etc/consul.d/client/config.json >/dev/null << EOF
{
"client_addr": "0.0.0.0",
"advertise_addr": "10.141.141.14",
"datacenter": "nyc2",
"data_dir": "/var/consul",
"encrypt": "X4SYOinf2pTAcAHRhpj7dA==",
"log_level": "INFO",
"enable_syslog": true,
"start_join": ["10.141.141.10", "10.141.141.11", "10.141.141.12"]
}
EOF
sudo tee /etc/init/consul.conf >/dev/null << EOF
description "Consul server process"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
respawn
setuid consul
setgid consul
exec consul agent -config-dir /etc/consul.d/client
EOF
sudo service consul start
else
echo "not on slave4"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment