mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
Add changes from etcd-2.0 project
Add ERB template for generating etcd override files. Update the Vagrantfile to automatically generate etcd override files. Update the provisioning script for easier changes in the future.
This commit is contained in:
parent
4dacf840ed
commit
b5c8824e70
7 changed files with 39 additions and 41 deletions
2
docker-swarm-etcd/.gitignore
vendored
Normal file
2
docker-swarm-etcd/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
.vagrant
|
||||
*.defaults
|
||||
17
docker-swarm-etcd/Vagrantfile
vendored
17
docker-swarm-etcd/Vagrantfile
vendored
|
|
@ -5,9 +5,10 @@
|
|||
Vagrant.require_version ">= 1.6.0"
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
|
||||
# Require 'yaml' and 'fileutils' modules
|
||||
# Require 'yaml', 'fileutils', and 'erb' modules
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
require 'erb'
|
||||
|
||||
# Look for user-data file to configure/customize CoreOS boxes
|
||||
# No changes should need to be made to this file
|
||||
|
|
@ -17,6 +18,20 @@ USER_DATA = File.join(File.dirname(__FILE__), "user-data")
|
|||
# Be sure to edit servers.yml to provide correct IP addresses
|
||||
servers = YAML.load_file('servers.yml')
|
||||
|
||||
# Use config from YAML file to write out templates for etcd overrides
|
||||
template = File.join(File.dirname(__FILE__), 'etcd.defaults.erb')
|
||||
content = ERB.new File.new(template).read
|
||||
|
||||
etcd_initial_cluster = []
|
||||
servers.each do |servers|
|
||||
etcd_initial_cluster << "#{servers['name']}=http://#{servers['priv_ip']}:2380"
|
||||
end
|
||||
servers.each do |servers|
|
||||
ip = servers['priv_ip']
|
||||
target = File.join(File.dirname(__FILE__), "#{servers['name']}.defaults")
|
||||
File.open(target, 'w') { |f| f.write(content.result(binding)) }
|
||||
end
|
||||
|
||||
# Create and configure the VMs
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
# Override file for etcd Upstart script
|
||||
|
||||
# Environment variables
|
||||
env ETCD_INITIAL_CLUSTER="etcd-01=http://192.168.101.101:2380,etcd-02=http://192.168.101.102:2380,etcd-03=http://192.168.101.103:2380"
|
||||
env ETCD_INITIAL_CLUSTER_STATE="new"
|
||||
env ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
|
||||
env ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.101.101:2380"
|
||||
env ETCD_DATA_DIR="/var/etcd"
|
||||
env ETCD_LISTEN_PEER_URLS="http://192.168.101.101:2380"
|
||||
env ETCD_LISTEN_CLIENT_URLS="http://192.168.101.101:2379,http://127.0.0.1:2379"
|
||||
env ETCD_ADVERTISE_CLIENT_URLS="http://192.168.101.101:2379"
|
||||
env ETCD_NAME="etcd-01"
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# Override file for etcd Upstart script
|
||||
|
||||
# Environment variables
|
||||
env ETCD_INITIAL_CLUSTER="etcd-01=http://192.168.101.101:2380,etcd-02=http://192.168.101.102:2380,etcd-03=http://192.168.101.103:2380"
|
||||
env ETCD_INITIAL_CLUSTER_STATE="new"
|
||||
env ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
|
||||
env ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.101.102:2380"
|
||||
env ETCD_DATA_DIR="/var/etcd"
|
||||
env ETCD_LISTEN_PEER_URLS="http://192.168.101.102:2380"
|
||||
env ETCD_LISTEN_CLIENT_URLS="http://192.168.101.102:2379,http://127.0.0.1:2379"
|
||||
env ETCD_ADVERTISE_CLIENT_URLS="http://192.168.101.102:2379"
|
||||
env ETCD_NAME="etcd-02"
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# Override file for etcd Upstart script
|
||||
|
||||
# Environment variables
|
||||
env ETCD_INITIAL_CLUSTER="etcd-01=http://192.168.101.101:2380,etcd-02=http://192.168.101.102:2380,etcd-03=http://192.168.101.103:2380"
|
||||
env ETCD_INITIAL_CLUSTER_STATE="new"
|
||||
env ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
|
||||
env ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.101.103:2380"
|
||||
env ETCD_DATA_DIR="/var/etcd"
|
||||
env ETCD_LISTEN_PEER_URLS="http://192.168.101.103:2380"
|
||||
env ETCD_LISTEN_CLIENT_URLS="http://192.168.101.103:2379,http://127.0.0.1:2379"
|
||||
env ETCD_ADVERTISE_CLIENT_URLS="http://192.168.101.103:2379"
|
||||
env ETCD_NAME="etcd-03"
|
||||
13
docker-swarm-etcd/etcd.defaults.erb
Normal file
13
docker-swarm-etcd/etcd.defaults.erb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Override file for etcd Upstart script
|
||||
# Generated from etcd.override.erb by Vagrant
|
||||
|
||||
# Environment variables
|
||||
export ETCD_INITIAL_CLUSTER="<%= etcd_initial_cluster.join(',') %>"
|
||||
export ETCD_INITIAL_CLUSTER_STATE="new"
|
||||
export ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
|
||||
export ETCD_INITIAL_ADVERTISE_PEER_URLS="http://<%= servers['priv_ip'] %>:2380"
|
||||
export ETCD_DATA_DIR="/var/etcd"
|
||||
export ETCD_LISTEN_PEER_URLS="http://<%= servers['priv_ip'] %>:2380"
|
||||
export ETCD_LISTEN_CLIENT_URLS="http://<%= servers['priv_ip'] %>:2379,http://127.0.0.1:2379"
|
||||
export ETCD_ADVERTISE_CLIENT_URLS="http://<%= servers['priv_ip'] %>:2379"
|
||||
export ETCD_NAME="<%= servers['name'] %>"
|
||||
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
# Define a couple variables for easier future modifications
|
||||
VERS="v2.0.9"
|
||||
FNAME="etcd-$VERS-linux-amd64.tar.gz"
|
||||
BASENAME="etcd-$VERS-linux-amd64"
|
||||
FNAME="$BASENAME.tar.gz"
|
||||
URL="https://github.com/coreos/etcd/releases/download/$VERS/$FNAME"
|
||||
|
||||
# Install curl if needed
|
||||
|
|
@ -21,14 +22,14 @@ if [[ ! -e /usr/local/bin/etcd ]]; then
|
|||
tar xzvf $FNAME
|
||||
|
||||
# Move etcd and etcdctl to /usr/local/bin
|
||||
cd etcd-v2.0.9-linux-amd64
|
||||
cd $BASENAME
|
||||
sudo mv etcd /usr/local/bin/
|
||||
sudo mv etcdctl /usr/local/bin/
|
||||
cd ..
|
||||
|
||||
# Remove etcd download and directory
|
||||
rm $FNAME
|
||||
rm -rf etcd-v2.0.9-linux-amd64
|
||||
rm -rf $BASENAME
|
||||
fi
|
||||
|
||||
# Create etcd data directory if not already present
|
||||
|
|
@ -38,4 +39,7 @@ fi
|
|||
|
||||
# Copy files into the correct locations; requires shared folders
|
||||
sudo cp /vagrant/etcd.conf /etc/init/etcd.conf
|
||||
sudo cp /vagrant/$HOSTNAME.override /etc/init/etcd.override
|
||||
sudo cp /vagrant/$HOSTNAME.defaults /etc/default/etcd
|
||||
|
||||
# Restart if already running; otherwise, start etcd.
|
||||
sudo initctl status etcd && initctl restart etcd || initctl start etcd
|
||||
|
|
|
|||
Loading…
Reference in a new issue