Skip to content

Commit 3096805

Browse files
author
Christian Requena
committed
Refactor nodejs default recipe to support upgrades and downgrades.
1 parent 239bb25 commit 3096805

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

opsworks_nodejs/recipes/default.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
local_nodejs_up_to_date = ::File.exists?("/usr/local/bin/node") && system("/usr/local/bin/node -v | grep -q '#{node[:opsworks_nodejs][:version]}'")
2+
13
case node[:platform]
24
when 'debian', 'ubuntu'
35
remote_file "/tmp/#{node[:opsworks_nodejs][:deb]}" do
46
source node[:opsworks_nodejs][:deb_url]
57
action :create_if_missing
68
not_if do
7-
::File.exists?("/usr/local/bin/node") &&
8-
system("/usr/local/bin/node -v | grep -q '#{node[:opsworks_nodejs][:version]}'")
9+
local_nodejs_up_to_date
10+
end
11+
end
12+
13+
execute "Remove old node.js versions due to update" do
14+
command "dpkg --purge nodejs"
15+
only_if do
16+
::File.exists?("/tmp/#{node[:opsworks_nodejs][:deb]}")
917
end
1018
end
1119

12-
apt_package "Install node.js #{node[:opsworks_nodejs][:version]}" do
13-
source "/tmp/#{node[:opsworks_nodejs][:deb]}"
20+
execute "Install node.js #{node[:opsworks_nodejs][:version]}" do
21+
cwd "/tmp"
22+
command "dpkg -i /tmp/#{node[:opsworks_nodejs][:deb]}"
1423
only_if do
1524
::File.exists?("/tmp/#{node[:opsworks_nodejs][:deb]}")
1625
end
@@ -21,13 +30,14 @@
2130
source node[:opsworks_nodejs][:rpm_url]
2231
action :create_if_missing
2332
not_if do
24-
::File.exists?("/usr/local/bin/node") &&
25-
system("/usr/local/bin/node -v | grep -q '#{node[:opsworks_nodejs][:version]}'")
33+
local_nodejs_up_to_date
2634
end
2735
end
2836

2937
rpm_package "Install node.js #{node[:opsworks_nodejs][:version]}" do
3038
source "/tmp/#{node[:opsworks_nodejs][:rpm]}"
39+
action :upgrade
40+
options "--oldpackage"
3141
only_if do
3242
::File.exists?("/tmp/#{node[:opsworks_nodejs][:rpm]}")
3343
end

0 commit comments

Comments
 (0)