From e0820892d4dffad495747a0c1151ce5a87b1ad13 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Tue, 5 Nov 2019 23:37:15 +0800 Subject: [PATCH 1/5] Install `consul`, when finding a newer version. --- cookbooks/consul/install.rb | 38 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/cookbooks/consul/install.rb b/cookbooks/consul/install.rb index 5fe4fb2..db1fffa 100644 --- a/cookbooks/consul/install.rb +++ b/cookbooks/consul/install.rb @@ -2,6 +2,7 @@ # Calculating the latest `consul` version: # ------------------------------------------- download_url = '' +tag_version = '' begin require 'net/http' @@ -26,22 +27,27 @@ end # Main Part # ------------------------------------------- -# Download: -execute "wget #{download_url} -O #{node['consul']['tmp_path']}" +# バージョン確認して、アップデート必要かどうか確認 +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/' + # 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 -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 From 45fe078188a7ec9b8f5f837690b5f1e1512fe9f6 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Tue, 5 Nov 2019 23:39:25 +0800 Subject: [PATCH 2/5] Install `consul-template` when finding a newer version. --- cookbooks/consul-template/install.rb | 35 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/cookbooks/consul-template/install.rb b/cookbooks/consul-template/install.rb index f938c32..1172339 100644 --- a/cookbooks/consul-template/install.rb +++ b/cookbooks/consul-template/install.rb @@ -2,6 +2,7 @@ # Calculating the latest `consul-template` version: # ------------------------------------------- download_url = '' +tag_version = '' begin require 'net/http' @@ -26,22 +27,26 @@ end # Main Part # ------------------------------------------- -# Download: -execute "wget #{download_url} -O #{node['consul-template']['tmp_path']}" +# バージョン確認して、アップデート必要かどうか確認 +result = run_command("consul-template --version 2>&1 | grep #{tag_version}", error: false) +if result.exit_status != 0 + # Download: + execute "wget #{download_url} -O #{node['consul-template']['tmp_path']}" -# Unzip: -execute "unzip -qo #{node['consul-template']['tmp_path']}" do - cwd '/opt/consul/bin/' -end + # Unzip: + execute "unzip -qo #{node['consul-template']['tmp_path']}" do + cwd '/opt/consul/bin/' + end -file '/opt/consul/bin/consul-template' do - owner 'root' - group 'root' - mode '755' -end + file '/opt/consul/bin/consul-template' do + owner 'root' + group 'root' + mode '755' + end -# Create link: -link '/usr/local/bin/consul-template' do - user 'root' - to '/opt/consul/bin/consul-template' + # Create link: + link '/usr/local/bin/consul-template' do + user 'root' + to '/opt/consul/bin/consul-template' + end end From a8b637a51eeafae89b614079c47c0294d61afe07 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Wed, 6 Nov 2019 00:00:30 +0800 Subject: [PATCH 3/5] 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 From dc6b5a2f01a7840b701f14c5d25119b8c2b41e44 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Wed, 6 Nov 2019 00:02:51 +0800 Subject: [PATCH 4/5] 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 From 40e7c266567e29727529a4cb9133dde37cec81ce Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Fri, 8 Nov 2019 00:27:53 +0800 Subject: [PATCH 5/5] Install `nginx-build` when finding a newer version. --- cookbooks/nginx/build.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cookbooks/nginx/build.rb b/cookbooks/nginx/build.rb index 8ec162c..0851101 100644 --- a/cookbooks/nginx/build.rb +++ b/cookbooks/nginx/build.rb @@ -50,12 +50,17 @@ rescue raise 'Cannot connect to http://github.com.' end -# Download `nginx-build`: -execute "wget #{nginxbuild} -O #{TARBALL}" -execute "tar xf #{TARBALL} && chown webadm:webadm #{NGINXBUILD}" do - user USER - cwd WORKDIR +# バージョン確認して、アップデート必要かどうか確認 +result = run_command("/home/webadm/nginx-build/nginx-build --version | grep #{tag_version}", error: false) +if result.exit_status != 0 + # Download `nginx-build`: + execute "wget #{nginxbuild} -O #{TARBALL}" + + execute "tar xf #{TARBALL} && chown webadm:webadm #{NGINXBUILD}" do + user USER + cwd WORKDIR + end end # Deploy `configure.sh`: