From dc6b5a2f01a7840b701f14c5d25119b8c2b41e44 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Wed, 6 Nov 2019 00:02:51 +0800 Subject: [PATCH] Install `prometheus` when finding a newer version. --- cookbooks/prometheus/install.rb | 52 +++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/cookbooks/prometheus/install.rb b/cookbooks/prometheus/install.rb index a1441bc..3891116 100644 --- a/cookbooks/prometheus/install.rb +++ b/cookbooks/prometheus/install.rb @@ -1,6 +1,9 @@ prometheus_url = '' prometheus_bin = '' +vtag = '' +tag = '' + # Calculate the Download URL: begin require 'net/http' @@ -22,28 +25,33 @@ rescue raise 'Cannot connect to http://github.com.' end -# Download: -TMP = "/tmp/#{prometheus_bin}" -execute "wget #{prometheus_url} -O #{TMP}" +# バージョン確認して、アップデート必要かどうか確認 +result = run_command("prometheus --version 2>&1 | grep #{tag}", error: false) +if result.exit_status != 0 + # Download: + TMP = "/tmp/#{prometheus_bin}" -# Install: -directory node['prometheus']['storage'] do - owner 'root' - group 'root' - mode '755' -end - -execute "tar zxf #{TMP} -C #{node['prometheus']['storage']} --strip-components 1" - -# 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" + execute "wget #{prometheus_url} -O #{TMP}" + + # Install: + directory node['prometheus']['storage'] do + owner 'root' + group 'root' + mode '755' + end + + execute "tar zxf #{TMP} -C #{node['prometheus']['storage']} --strip-components 1" + + # 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 end