Skip to content

Commit

Permalink
Merge pull request #1629 from moofish32/update_terraform_rhel7
Browse files Browse the repository at this point in the history
Add support for RHEL7/Systemd in Terraform example
  • Loading branch information
slackpad committed Mar 10, 2016
2 parents 01ae1e7 + b4dfd0f commit 0b581b3
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 296 deletions.
2 changes: 1 addition & 1 deletion terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This folder contains modules for Terraform that can setup Consul for
various systems. The infrastructure provider that is used is designated
by the folder above. See the `variables.tf` file in each for more documentation.
by the folder above. See the `variables.tf` file in each for more documentation.
16 changes: 6 additions & 10 deletions terraform/aws/consul.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ resource "aws_instance" "server" {
}

provisioner "file" {
source = "${path.module}/scripts/${var.platform}/upstart.conf"
destination = "/tmp/upstart.conf"
source = "${path.module}/scripts/${lookup(var.service_conf, var.platform)}"
destination = "/tmp/${lookup(var.service_conf_dest, var.platform)}"
}

provisioner "file" {
source = "${path.module}/scripts/${var.platform}/upstart-join.conf"
destination = "/tmp/upstart-join.conf"
}

provisioner "remote-exec" {
inline = [
Expand All @@ -34,15 +30,15 @@ resource "aws_instance" "server" {

provisioner "remote-exec" {
scripts = [
"${path.module}/scripts/${var.platform}/install.sh",
"${path.module}/scripts/${var.platform}/server.sh",
"${path.module}/scripts/${var.platform}/service.sh",
"${path.module}/scripts/install.sh",
"${path.module}/scripts/service.sh",
"${path.module}/scripts/ip_tables.sh",
]
}
}

resource "aws_security_group" "consul" {
name = "consul"
name = "consul_${var.platform}"
description = "Consul internal traffic + maintenance."

// These are for internal traffic
Expand Down
39 changes: 0 additions & 39 deletions terraform/aws/scripts/centos6/install.sh

This file was deleted.

15 changes: 0 additions & 15 deletions terraform/aws/scripts/centos6/server.sh

This file was deleted.

5 changes: 0 additions & 5 deletions terraform/aws/scripts/centos6/service.sh

This file was deleted.

25 changes: 0 additions & 25 deletions terraform/aws/scripts/centos6/upstart-join.conf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description "Consul agent"

start on runlevel [2345]
start on started networking
stop on runlevel [!2345]

respawn
Expand All @@ -24,3 +24,4 @@ script
${CONSUL_FLAGS} \
>>/var/log/consul.log 2>&1
end script

53 changes: 53 additions & 0 deletions terraform/aws/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
set -e

echo "Installing dependencies..."
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get update -y
sudo apt-get install -y unzip
else
sudo yum update -y
sudo yum install -y unzip wget
fi


echo "Fetching Consul..."
CONSUL=0.6.3
cd /tmp
wget https://releases.hashicorp.com/consul/${CONSUL}/consul_${CONSUL}_linux_amd64.zip -O consul.zip

echo "Installing Consul..."
unzip consul.zip >/dev/null
chmod +x consul
sudo mv consul /usr/local/bin/consul
sudo mkdir -p /opt/consul/data

# Read from the file we created
SERVER_COUNT=$(cat /tmp/consul-server-count | tr -d '\n')
CONSUL_JOIN=$(cat /tmp/consul-server-addr | tr -d '\n')

# Write the flags to a temporary file
cat >/tmp/consul_flags << EOF
CONSUL_FLAGS="-server -bootstrap-expect=${SERVER_COUNT} -join=${CONSUL_JOIN} -data-dir=/opt/consul/data"
EOF

if [ -f /tmp/upstart.conf ];
then
echo "Installing Upstart service..."
sudo mkdir -p /etc/consul.d
sudo mkdir -p /etc/service
sudo chown root:root /tmp/upstart.conf
sudo mv /tmp/upstart.conf /etc/init/consul.conf
sudo chmod 0644 /etc/init/consul.conf
sudo mv /tmp/consul_flags /etc/service/consul
sudo chmod 0644 /etc/service/consul
else
echo "Installing Systemd service..."
sudo mkdir -p /etc/systemd/system/consul.d
sudo chown root:root /tmp/consul.service
sudo mv /tmp/consul.service /etc/systemd/system/consul.service
sudo chmod 0644 /etc/systemd/system/consul.service
sudo mv /tmp/consul_flags /etc/sysconfig/consul
sudo chown root:root /etc/sysconfig/consul
sudo chmod 0644 /etc/sysconfig/consul
fi
12 changes: 12 additions & 0 deletions terraform/aws/scripts/ip_tables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

sudo iptables -I INPUT -s 0/0 -p tcp --dport 8300 -j ACCEPT
sudo iptables -I INPUT -s 0/0 -p tcp --dport 8301 -j ACCEPT
sudo iptables -I INPUT -s 0/0 -p tcp --dport 8302 -j ACCEPT

if [ -d /etc/sysconfig ]; then
sudo iptables-save | sudo tee /etc/sysconfig/iptables
else
sudo iptables-save | sudo tee /etc/iptables.rules
fi
37 changes: 0 additions & 37 deletions terraform/aws/scripts/rhel6/install.sh

This file was deleted.

15 changes: 0 additions & 15 deletions terraform/aws/scripts/rhel6/server.sh

This file was deleted.

5 changes: 0 additions & 5 deletions terraform/aws/scripts/rhel6/service.sh

This file was deleted.

25 changes: 0 additions & 25 deletions terraform/aws/scripts/rhel6/upstart-join.conf

This file was deleted.

14 changes: 14 additions & 0 deletions terraform/aws/scripts/rhel_consul.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=consul agent
Requires=network-online.target
After=network-online.target

[Service]
EnvironmentFile=-/etc/sysconfig/consul
Restart=on-failure
ExecStart=/usr/local/bin/consul agent $CONSUL_FLAGS -config-dir=/etc/systemd/system/consul.d
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description "Consul agent"

start on runlevel [2345]
start on started network
stop on runlevel [!2345]

respawn
Expand Down
12 changes: 12 additions & 0 deletions terraform/aws/scripts/service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

echo "Starting Consul..."
if [ -x "$(command -v systemctl)" ]; then
echo "using systemctl"
sudo systemctl enable consul.service
sudo systemctl start consul
else
echo "using upstart"
sudo start consul
fi
35 changes: 0 additions & 35 deletions terraform/aws/scripts/ubuntu/install.sh

This file was deleted.

14 changes: 0 additions & 14 deletions terraform/aws/scripts/ubuntu/server.sh

This file was deleted.

5 changes: 0 additions & 5 deletions terraform/aws/scripts/ubuntu/service.sh

This file was deleted.

Loading

0 comments on commit 0b581b3

Please sign in to comment.