From a8b637a51eeafae89b614079c47c0294d61afe07 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Wed, 6 Nov 2019 00:00:30 +0800 Subject: [PATCH] Install `node_exporter` when finding a newer version. --- cookbooks/prometheus/node_exporter_install.rb | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/cookbooks/prometheus/node_exporter_install.rb b/cookbooks/prometheus/node_exporter_install.rb index 73c4d98..0eeab37 100644 --- a/cookbooks/prometheus/node_exporter_install.rb +++ b/cookbooks/prometheus/node_exporter_install.rb @@ -1,6 +1,9 @@ node_exporter_url = '' node_exporter_bin = '' +tag = '' +vtag = '' + # Calculate the Download URL: begin require 'net/http' @@ -21,28 +24,32 @@ rescue raise 'Cannot connect to http://github.com.' end -# Download: -TMP = "/tmp/#{node_exporter_bin}" +# バージョン確認して、アップデート必要かどうか確認 +result = run_command("node_exporter --version 2>&1 | grep #{tag}", error: false) +if result.exit_status != 0 + # Download: + TMP = "/tmp/#{node_exporter_bin}" -execute "wget #{node_exporter_url} -O #{TMP}" + execute "wget #{node_exporter_url} -O #{TMP}" -# Install: -directory node['node_exporter']['storage'] do - owner 'root' - group 'root' - mode '755' -end - -execute "tar zxf #{TMP} -C #{node['node_exporter']['storage']} --strip-components 1" - -# Change Owner and Permissions: -file "#{node['node_exporter']['storage']}node_exporter" do - owner 'root' - group 'root' - mode '755' -end - -# Create Link -link "#{node['node_exporter']['location']}node_exporter" do - to "#{node['node_exporter']['storage']}node_exporter" + # Install: + directory node['node_exporter']['storage'] do + owner 'root' + group 'root' + mode '755' + end + + execute "tar zxf #{TMP} -C #{node['node_exporter']['storage']} --strip-components 1" + + # Change Owner and Permissions: + file "#{node['node_exporter']['storage']}node_exporter" do + owner 'root' + group 'root' + mode '755' + end + + # Create Link + link "#{node['node_exporter']['location']}node_exporter" do + to "#{node['node_exporter']['storage']}node_exporter" + end end