itamae/cookbooks/prometheus/prometheus_install.rb

58 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2019-03-03 08:50:49 +00:00
prometheus_url = ''
prometheus_bin = ''
vtag = ''
tag = ''
2019-03-03 08:50:49 +00:00
# Calculate the Download URL:
begin
require 'net/http'
uri = URI.parse('https://github.com/prometheus/prometheus/releases/latest')
Timeout.timeout(3) do
response = Net::HTTP.get_response(uri)
2022-10-15 01:49:11 +00:00
vtag = $1 if response['location'] =~ %r{tag\/(v\d+\.\d+\.\d+)}
2019-03-03 08:50:49 +00:00
tag = vtag.sub(/^v/, '')
prometheus_bin = "#{node['prometheus']['prefix']}#{tag}#{node['prometheus']['postfix']}"
prometheus_url = "#{node['prometheus']['url']}/#{vtag}/#{prometheus_bin}"
end
rescue
# Abort the chef client process:
raise 'Cannot connect to http://github.com.'
end
# バージョン確認して、アップデート必要かどうか確認
result = run_command("prometheus --version 2>&1 | grep #{tag}", error: false)
if result.exit_status != 0
# Download:
TMP = "/tmp/#{prometheus_bin}"
2019-03-03 08:50:49 +00:00
execute "wget #{prometheus_url} -O #{TMP}"
2019-03-03 08:50:49 +00:00
# Install:
directory node['prometheus']['storage'] do
owner 'root'
group 'root'
mode '755'
end
2019-03-03 08:50:49 +00:00
execute "tar zxf #{TMP} -C #{node['prometheus']['storage']} --strip-components 1"
2019-03-03 08:50:49 +00:00
# Change Owner and Permissions:
file "#{node['prometheus']['storage']}prometheus" do
owner 'root'
group 'root'
mode '755'
end
# Create Link
link "#{node['prometheus']['location']}prometheus" do
to "#{node['prometheus']['storage']}prometheus"
end
2019-03-03 08:50:49 +00:00
end