Install from `deb` package.

This commit is contained in:
Kazuhiro MUSASHI 2020-11-22 16:00:00 +09:00
parent fe8b100a22
commit 39f8fc5bc1
6 changed files with 21 additions and 79 deletions

View File

@ -1,7 +1,5 @@
include_recipe './attributes.rb'
include_recipe './prerequisites.rb'
include_recipe './install.rb'
include_recipe './setup.rb'

View File

@ -1,3 +1,5 @@
package 'dnsmasq'
%w(dnsmasq resolvconf systemd-resolved).each do |s|
service s do
action :nothing

View File

@ -1,53 +1,20 @@
# -------------------------------------------
# Calculating the latest `consul` version:
# -------------------------------------------
download_url = ''
tag_version = ''
# Install `Consul`:
KEYSRV = "https://apt.releases.hashicorp.com/gpg"
ID = "A3219F7B"
begin
require 'net/http'
uri = URI.parse('https://www.consul.io/downloads.html')
Timeout.timeout(3) do
response = Net::HTTP.get_response(uri)
if response.body =~ /consul_(\d+\.\d+\.\d+)/
tag_version = $1
download_url = \
"#{node['consul']['base_binary_url']}#{tag_version}/consul_#{tag_version}_linux_#{node['consul']['arch']}.zip"
end
end
rescue
# Abort the chef client process:
raise 'Cannot connect to https://www.consul.io/downloads.html'
execute "apt-key adv --keyserver #{KEYSRV} --recv-keys #{ID}" do
not_if "apt-key list | grep #{ID}"
end
# -------------------------------------------
# Main Part
# -------------------------------------------
# Retrieve the Ubuntu code:
DIST = run_command('lsb_release -cs').stdout.chomp
# バージョン確認して、アップデート必要かどうか確認
result = run_command("consul version | grep #{tag_version}", error: false)
if result.exit_status != 0
# Download:
execute "wget #{download_url} -O #{node['consul']['tmp_path']}"
# Unzip:
execute "unzip -qo #{node['consul']['tmp_path']}" do
cwd '/opt/consul/bin/'
end
file '/opt/consul/bin/consul' do
owner 'root'
group 'root'
mode '755'
end
# Create link:
link '/usr/local/bin/consul' do
user 'root'
to '/opt/consul/bin/consul'
end
# Deploy the `apt` sources:
template '/etc/apt/sources.list.d/consul.list' do
action :create
variables(distribution: DIST)
end
execute 'apt update'
package 'consul'

View File

@ -1,14 +0,0 @@
# Ensure that `unzip` and `dnsmasq` are available:
%w( unzip dnsmasq ).each do |p|
package p do
action :install
end
end
%w(/etc/consul.d /var/opt/consul /opt/consul/bin).each do |d|
directory d do
owner 'root'
group 'root'
mode '755'
end
end

View File

@ -1,12 +1,6 @@
remote_file '/etc/supervisor/conf.d/consul.conf' do
owner 'root'
group 'root'
mode '644'
end
template '/etc/consul.d/config.json' do
owner 'root'
group 'root'
owner 'consul'
group 'consul'
mode '644'
variables(manager: node['consul']['manager'],
@ -18,17 +12,11 @@ template '/etc/consul.d/config.json' do
end
remote_file '/etc/consul.d/service-consul.json' do
owner 'root'
group 'root'
owner 'consul'
group 'consul'
mode '644'
end
execute 'Reload supervisor' do
user 'root'
command '/usr/bin/supervisorctl update'
end
# iptables settings here:
%w( 8300/tcp 8301/tcp 8301/udp 8500/tcp ).each do |port|
execute "ufw allow #{port}" do

View File

@ -0,0 +1 @@
deb [arch=amd64] https://apt.releases.hashicorp.com <%= @distribution %> main