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 './attributes.rb'
include_recipe './prerequisites.rb'
include_recipe './install.rb' include_recipe './install.rb'
include_recipe './setup.rb' include_recipe './setup.rb'

View File

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

View File

@ -1,53 +1,20 @@
# ------------------------------------------- # Install `Consul`:
# Calculating the latest `consul` version: KEYSRV = "https://apt.releases.hashicorp.com/gpg"
# ------------------------------------------- ID = "A3219F7B"
download_url = ''
tag_version = ''
begin execute "apt-key adv --keyserver #{KEYSRV} --recv-keys #{ID}" do
require 'net/http' not_if "apt-key list | grep #{ID}"
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'
end end
# ------------------------------------------- # Retrieve the Ubuntu code:
# Main Part DIST = run_command('lsb_release -cs').stdout.chomp
# -------------------------------------------
# バージョン確認して、アップデート必要かどうか確認 # Deploy the `apt` sources:
result = run_command("consul version | grep #{tag_version}", error: false) template '/etc/apt/sources.list.d/consul.list' do
if result.exit_status != 0 action :create
# Download: variables(distribution: DIST)
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
end 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 template '/etc/consul.d/config.json' do
owner 'root' owner 'consul'
group 'root' group 'consul'
mode '644' mode '644'
variables(manager: node['consul']['manager'], variables(manager: node['consul']['manager'],
@ -18,17 +12,11 @@ template '/etc/consul.d/config.json' do
end end
remote_file '/etc/consul.d/service-consul.json' do remote_file '/etc/consul.d/service-consul.json' do
owner 'root' owner 'consul'
group 'root' group 'consul'
mode '644' mode '644'
end end
execute 'Reload supervisor' do
user 'root'
command '/usr/bin/supervisorctl update'
end
# iptables settings here: # iptables settings here:
%w( 8300/tcp 8301/tcp 8301/udp 8500/tcp ).each do |port| %w( 8300/tcp 8301/tcp 8301/udp 8500/tcp ).each do |port|
execute "ufw allow #{port}" do execute "ufw allow #{port}" do

View File

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