Adding rhel scripts and changes for rhel paramaters
This commit is contained in:
parent
f94e70d66e
commit
1bb019423d
|
@ -1,12 +1,13 @@
|
||||||
resource "aws_instance" "server" {
|
resource "aws_instance" "server" {
|
||||||
ami = "${lookup(var.ami, var.region)}"
|
ami = "${lookup(var.ami, concat(var.region, "-", var.platform))}"
|
||||||
|
#ami = "${lookup(var.ami, var.region, var.platform)}"
|
||||||
instance_type = "${var.instance_type}"
|
instance_type = "${var.instance_type}"
|
||||||
key_name = "${var.key_name}"
|
key_name = "${var.key_name}"
|
||||||
count = "${var.servers}"
|
count = "${var.servers}"
|
||||||
security_groups = ["${aws_security_group.consul.name}"]
|
security_groups = ["${aws_security_group.consul.name}"]
|
||||||
|
|
||||||
connection {
|
connection {
|
||||||
user = "ubuntu"
|
user = "${lookup(var.user, var.platform)}"
|
||||||
key_file = "${var.key_path}"
|
key_file = "${var.key_path}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
36
terraform/aws/scripts/rhel/install.sh
Normal file
36
terraform/aws/scripts/rhel/install.sh
Normal file
|
@ -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..."
|
||||||
|
sudo yum update -y
|
||||||
|
sudo 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
|
||||||
|
sudo chmod +x consul
|
||||||
|
sudo mv consul /usr/local/bin/consul
|
||||||
|
sudo mkdir -p /etc/consul.d
|
||||||
|
sudo mkdir -p /mnt/consul
|
||||||
|
sudo mkdir -p /etc/service
|
||||||
|
|
||||||
|
# Setup the join address
|
||||||
|
cat >/tmp/consul-join << EOF
|
||||||
|
export CONSUL_JOIN="${JOIN_ADDRS}"
|
||||||
|
EOF
|
||||||
|
sudo mv /tmp/consul-join /etc/service/consul-join
|
||||||
|
chmod 0644 /etc/service/consul-join
|
||||||
|
|
||||||
|
echo "Installing Upstart service..."
|
||||||
|
sudo chown root:root /tmp/upstart.conf
|
||||||
|
sudo chown root:root /tmp/upstart-join.conf
|
||||||
|
sudo mv /tmp/upstart.conf /etc/init/consul.conf
|
||||||
|
sudo mv /tmp/upstart-join.conf /etc/init/consul-join.conf
|
||||||
|
echo "Installed upstart"
|
||||||
|
sudo initctl list
|
15
terraform/aws/scripts/rhel/server.sh
Executable file
15
terraform/aws/scripts/rhel/server.sh
Executable file
|
@ -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
|
||||||
|
sudo mv /tmp/consul_flags /etc/service/consul
|
||||||
|
sudo chown root:root /etc/service/consul
|
||||||
|
sudo chmod 0644 /etc/service/consul
|
5
terraform/aws/scripts/rhel/service.sh
Executable file
5
terraform/aws/scripts/rhel/service.sh
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "Starting Consul..."
|
||||||
|
sudo start consul
|
25
terraform/aws/scripts/rhel/upstart-join.conf
Normal file
25
terraform/aws/scripts/rhel/upstart-join.conf
Normal file
|
@ -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
|
28
terraform/aws/scripts/rhel/upstart.conf
Normal file
28
terraform/aws/scripts/rhel/upstart.conf
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
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
|
||||||
|
# stop consul will not mark node as failed but left
|
||||||
|
#kill signal 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
|
|
@ -1,7 +1,26 @@
|
||||||
|
variable "platform" {
|
||||||
|
default = "ubuntu"
|
||||||
|
description = "The region of AWS, for AMI lookups."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "user" {
|
||||||
|
default = "ubuntu"
|
||||||
|
description = "The region of AWS, for AMI lookups."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "user" {
|
||||||
|
default = {
|
||||||
|
ubuntu = "ubuntu"
|
||||||
|
rhel = "ec2-user"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
variable "ami" {
|
variable "ami" {
|
||||||
default = {
|
default = {
|
||||||
us-east-1 = "ami-3acc7a52"
|
us-east-1-ubuntu = "ami-3acc7a52"
|
||||||
us-west-2 = "ami-37501207"
|
us-west-2-ubuntu = "ami-37501207"
|
||||||
|
us-east-1-rhel = "ami-b0fed2d8"
|
||||||
|
us-west-2-rhel = "ami-4dbf9e7d"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +43,7 @@ variable "servers" {
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "instance_type" {
|
variable "instance_type" {
|
||||||
default = "m1.small"
|
default = "m3.medium"
|
||||||
description = "The instance type to launch."
|
description = "The instance type to launch."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue