From 993d8f6f7ede1076ebde8981166c6c36328912a8 Mon Sep 17 00:00:00 2001 From: Sathiya Shunmugasundaram Date: Tue, 2 Jun 2015 20:57:35 -0400 Subject: [PATCH] centos6 Initial commit --- terraform/aws/README.md | 4 ++- terraform/aws/scripts/centos6/install.sh | 36 +++++++++++++++++++ terraform/aws/scripts/centos6/server.sh | 15 ++++++++ terraform/aws/scripts/centos6/service.sh | 5 +++ .../aws/scripts/centos6/upstart-join.conf | 25 +++++++++++++ terraform/aws/scripts/centos6/upstart.conf | 26 ++++++++++++++ terraform/aws/variables.tf | 3 ++ 7 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 terraform/aws/scripts/centos6/install.sh create mode 100755 terraform/aws/scripts/centos6/server.sh create mode 100755 terraform/aws/scripts/centos6/service.sh create mode 100644 terraform/aws/scripts/centos6/upstart-join.conf create mode 100644 terraform/aws/scripts/centos6/upstart.conf diff --git a/terraform/aws/README.md b/terraform/aws/README.md index 441afe34c0..d4f9986fb0 100644 --- a/terraform/aws/README.md +++ b/terraform/aws/README.md @@ -14,4 +14,6 @@ terraform apply -var 'key_name=consul' -var 'key_path=/Users/xyz/consul.pem' -va To run rhel6, run like below -terraform apply -var 'key_name=consul' -var 'key_path=/Users/xyz/consul.pem' -var 'platform=rhel6' \ No newline at end of file +terraform apply -var 'key_name=consul' -var 'key_path=/Users/xyz/consul.pem' -var 'platform=rhel6' + +For centos6 platform, for the default AMI, you need to accept the AWS market place terms and conditions. When you launch first time, you will get an error with an URL to accept the terms and conditions. \ No newline at end of file diff --git a/terraform/aws/scripts/centos6/install.sh b/terraform/aws/scripts/centos6/install.sh new file mode 100644 index 0000000000..045e07b51f --- /dev/null +++ b/terraform/aws/scripts/centos6/install.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -e + +# Read the address to join from the file we provisioned +JOIN_ADDRS=$(cat /tmp/consul-server-addr | tr -d '\n') + +echo "Installing dependencies..." +yum update -y +yum install -y unzip wget + +echo "Fetching Consul..." +cd /tmp +wget https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip -O consul.zip + +echo "Installing Consul..." +unzip consul.zip >/dev/null +chmod +x consul +mv consul /usr/local/bin/consul +mkdir -p /etc/consul.d +mkdir -p /mnt/consul +mkdir -p /etc/service + +#Enable consul port in iptables +echo "Allow port 8301 in iptables" +iptables -I INPUT -s 0/0 -p tcp --dport 8301 -j ACCEPT + +# Setup the join address +cat >/tmp/consul-join << EOF +export CONSUL_JOIN="${JOIN_ADDRS}" +EOF +mv /tmp/consul-join /etc/service/consul-join +chmod 0644 /etc/service/consul-join + +echo "Installing Upstart service..." +mv /tmp/upstart.conf /etc/init/consul.conf +mv /tmp/upstart-join.conf /etc/init/consul-join.conf diff --git a/terraform/aws/scripts/centos6/server.sh b/terraform/aws/scripts/centos6/server.sh new file mode 100755 index 0000000000..64e9cadfa8 --- /dev/null +++ b/terraform/aws/scripts/centos6/server.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +# Read from the file we created +SERVER_COUNT=$(cat /tmp/consul-server-count | tr -d '\n') + +# Write the flags to a temporary file +cat >/tmp/consul_flags << EOF +export CONSUL_FLAGS="-server -bootstrap-expect=${SERVER_COUNT} -data-dir=/mnt/consul" +EOF + +# Write it to the full service file +mv /tmp/consul_flags /etc/service/consul +chown root:root /etc/service/consul +chmod 0644 /etc/service/consul diff --git a/terraform/aws/scripts/centos6/service.sh b/terraform/aws/scripts/centos6/service.sh new file mode 100755 index 0000000000..c7ae0e2aee --- /dev/null +++ b/terraform/aws/scripts/centos6/service.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +echo "Starting Consul..." +start consul diff --git a/terraform/aws/scripts/centos6/upstart-join.conf b/terraform/aws/scripts/centos6/upstart-join.conf new file mode 100644 index 0000000000..16343d8759 --- /dev/null +++ b/terraform/aws/scripts/centos6/upstart-join.conf @@ -0,0 +1,25 @@ +description "Join the consul cluster" + +start on started consul +stop on stopped consul + +task + +script + if [ -f "/etc/service/consul-join" ]; then + . /etc/service/consul-join + fi + + # Keep trying to join until it succeeds + set +e + while :; do + logger -t "consul-join" "Attempting join: ${CONSUL_JOIN}" + /usr/local/bin/consul join \ + ${CONSUL_JOIN} \ + >>/var/log/consul-join.log 2>&1 + [ $? -eq 0 ] && break + sleep 5 + done + + logger -t "consul-join" "Join success!" +end script diff --git a/terraform/aws/scripts/centos6/upstart.conf b/terraform/aws/scripts/centos6/upstart.conf new file mode 100644 index 0000000000..7c050dc011 --- /dev/null +++ b/terraform/aws/scripts/centos6/upstart.conf @@ -0,0 +1,26 @@ +description "Consul agent" + +start on runlevel [2345] +stop on runlevel [!2345] + +respawn +# This is to avoid Upstart re-spawning the process upon `consul leave` +normal exit 0 INT + +script + if [ -f "/etc/service/consul" ]; then + . /etc/service/consul + fi + + # Make sure to use all our CPUs, because Consul can block a scheduler thread + export GOMAXPROCS=`nproc` + + # Get the public IP + BIND=`ifconfig eth0 | grep "inet addr" | awk '{ print substr($2,6) }'` + + exec /usr/local/bin/consul agent \ + -config-dir="/etc/consul.d" \ + -bind=$BIND \ + ${CONSUL_FLAGS} \ + >>/var/log/consul.log 2>&1 +end script diff --git a/terraform/aws/variables.tf b/terraform/aws/variables.tf index 94c0e310f7..cb4aa4c073 100644 --- a/terraform/aws/variables.tf +++ b/terraform/aws/variables.tf @@ -7,6 +7,7 @@ variable "user" { default = { ubuntu = "ubuntu" rhel6 = "ec2-user" + centos6 = "root" } } @@ -17,6 +18,8 @@ variable "ami" { us-west-2-ubuntu = "ami-57e8d767" us-east-1-rhel6 = "ami-b0fed2d8" us-west-2-rhel6 = "ami-2faa861f" + us-east-1-centos6 = "ami-c2a818aa" + us-west-2-centos6 = "ami-81d092b1" } }