Finish consul update

Add more idempotency features to provisioning script. Add Consul configuration file for use with initctl on Ubuntu. Update IP addresses in use. Re-arrange provisioners in Vagrantfile.
This commit is contained in:
Scott Lowe 2015-10-12 15:13:56 -06:00
parent 80bf151f1c
commit b4cc1e3052
6 changed files with 54 additions and 33 deletions

32
consul/Vagrantfile vendored
View file

@ -2,8 +2,8 @@
# vi: set ft=ruby :
# Specify Vagrant version, Vagrant API version, and Vagrant clone location
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
Vagrant.require_version '>= 1.6.0'
VAGRANTFILE_API_VERSION = '2'
ENV['VAGRANT_VMWARE_CLONE_DIRECTORY'] = '~/.vagrant'
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_fusion'
#ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_appcatalyst'
@ -23,38 +23,38 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Iterate through entries in YAML file to create VMs
servers.each do |server|
config.vm.define server["name"] do |srv|
config.vm.define server['name'] do |srv|
# Don't check for box updates
srv.vm.box_check_update = false
# Specify hostname and Vagrant box
srv.vm.hostname = server["name"]
srv.vm.box = server["box"]
srv.vm.hostname = server['name']
srv.vm.box = server['box']
# Assign an additional static private network
srv.vm.network "private_network", ip: server["priv_ip"]
srv.vm.network 'private_network', ip: server['priv_ip']
# Specify default synced folder; requires VMware Tools
srv.vm.synced_folder ".", "/vagrant", disabled: true
# Provision consul to the VMs
srv.vm.provision "shell", path: "consul.sh"
srv.vm.synced_folder '.', '/vagrant', disabled: true
# Copy in the Consul configuration files
srv.vm.provision "file", source: "bootstrap.json", destination: "/etc/consul.d/bootstrap/config.json"
srv.vm.provision "file", source: "server.json", destination: "/etc/consul.d/server/config.json"
srv.vm.provision 'file', source: 'server.json', destination: '/home/vagrant/config.json'
srv.vm.provision 'file', source: 'consul.conf', destination: '/home/vagrant/consul.conf'
# Provision consul to the VMs
srv.vm.provision 'shell', path: 'consul.sh'
# Configure VMs with RAM and CPUs per settings in servers.yml
srv.vm.provider :vmware_fusion do |vmw|
vmw.vmx["memsize"] = server["ram"]
vmw.vmx["numvcpus"] = server["vcpu"]
vmw.vmx['memsize'] = server['ram']
vmw.vmx['numvcpus'] = server['vcpu']
end # srv.vm.provider vmware_fusion
# Configure VMs with RAM and CPUs per settings in servers.yml
srv.vm.provider :vmware_appcatalyst do |vmw|
vmw.vmx["memsize"] = server["ram"]
vmw.vmx["numvcpus"] = server["vcpu"]
vmw.vmx['memsize'] = server['ram']
vmw.vmx['numvcpus'] = server['vcpu']
end # srv.vm.provider vmware_appcatalyst
end # config.vm.define
end # servers.each

View file

@ -1,8 +0,0 @@
{
"bootstrap": true,
"server": true,
"datacenter": "dc1",
"data_dir": "/tmp",
"log_level": "INFO",
"enable_syslog": true
}

19
consul/consul.conf Normal file
View file

@ -0,0 +1,19 @@
description "Consul server process"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
script
if [ -f "/etc/service/consul" ]; then
. /etc/service/consul
fi
export GOMAXPROCS=`nproc`
exec /usr/local/bin/consul agent \
-config-dir="/etc/consul.d/server" \
${CONSUL_FLAGS} \
>>/var/log/consul.log 2>&1
end script

View file

@ -1,11 +1,17 @@
#!/bin/bash
# Update list of packages
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
# Install unzip package, needed to decompress Consul download
export DEBIAN_FRONTEND=noninteractive
sudo apt-get -y install unzip
# Install packages as needed
if [[ ! -e /usr/bin/curl ]]; then
apt-get -yqq install curl
fi
if [[ ! -e /usr/bin/unzip ]]; then
apt-get -yqq install unzip
fi
# Download and install Consul binary, if needed
if [[ ! -e /usr/local/bin/consul ]];then
@ -21,8 +27,12 @@ if [[ ! -e /usr/local/bin/consul ]];then
sudo mv consul /usr/local/bin/
fi
# Create consul user
useradd -M -d /var/consul -r -s /usr/bin/nologin consul
# Create consul user, if it doesn't already exist
if [ -z "$(getent passwd consul)" ]; then
useradd -M -d /var/consul -r -s /usr/bin/nologin consul
else
echo "Consul user already created."
fi
# Create and configure Consul working directory
sudo mkdir -p /var/consul

View file

@ -5,5 +5,5 @@
"data_dir": "/tmp",
"log_level": "INFO",
"enable_syslog": true,
"start_join": ["192.168.1.101", "192.168.1.102", "192.168.1.103"]
"start_join": ["192.168.100.101", "192.168.100.102", "192.168.100.103"]
}

View file

@ -3,14 +3,14 @@
box: "slowe/ubuntu-trusty-x64"
ram: "512"
vcpu: "1"
priv_ip: 192.168.1.101
priv_ip: 192.168.100.101
- name: "consul-02"
box: "slowe/ubuntu-trusty-x64"
ram: "512"
vcpu: "1"
priv_ip: 192.168.1.102
priv_ip: 192.168.100.102
- name: "consul-03"
box: "slowe/ubuntu-trusty-x64"
ram: "512"
vcpu: "1"
priv_ip: 192.168.1.103
priv_ip: 192.168.100.103