Skip to content

Commit 3de3892

Browse files
committedNov 19, 2021
Set unified_mode on custom resources
Rework nssm_install resource to remove :before notification which does not work in unified mode in that case.
1 parent 9a7c963 commit 3de3892

File tree

6 files changed

+27
-45
lines changed

6 files changed

+27
-45
lines changed
 

‎metadata.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
maintainer_email 'systems-services-team@criteo.com'
66
license 'MIT'
77
description 'Installs/Configures NSSM'
8-
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
98
source_url 'https://github.com/criteo-cookbooks/nssm'
109
issues_url 'https://github.com/criteo-cookbooks/nssm/issues'
11-
version '5.0.0'
10+
version '5.1.0'
1211

13-
chef_version '>= 15.0'
12+
chef_version '>= 15.3'
1413

1514
supports 'windows'

‎resources/install.rb

+7-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
provides :nssm_install, platform: 'windows'
22

3+
unified_mode true
4+
35
property :source, String, identity: true, name_property: true
46
property :sha256, String, required: true
57

@@ -8,29 +10,21 @@
810
action :install do
911
src = new_resource.source
1012
basename = src.slice(src.rindex('/') + 1, src.rindex('.') - src.rindex('/') - 1)
11-
download_path = "#{Chef::Config[:file_cache_path]}/#{basename}.zip"
12-
extract_path = "#{Chef::Config[:file_cache_path]}/#{basename}"
1313
system = node['kernel']['machine'] == 'x86_64' ? 'win64' : 'win32'
14+
download_path = "#{Chef::Config[:file_cache_path]}/#{basename}.zip"
15+
extract_path = "#{Chef::Config[:file_cache_path]}/nssm"
1416
system_file = "#{extract_path}/#{basename}/#{system}/nssm.exe"
1517

1618
remote_file 'download nssm' do
17-
checksum new_resource.sha256
1819
path download_path
20+
checksum new_resource.sha256
1921
source src
20-
notifies :create, 'remote_file[install nssm]', :immediately
21-
end
22-
23-
directory extract_path do
24-
action :nothing
25-
recursive true
26-
subscribes :delete, 'remote_file[download nssm]', :before
2722
end
2823

2924
archive_file 'extract nssm' do
30-
action :extract
31-
destination extract_path
32-
overwrite false
3325
path download_path
26+
destination extract_path
27+
overwrite :auto
3428
end
3529

3630
remote_file 'install nssm' do
@@ -39,9 +33,3 @@
3933
only_if { ::File.exist? system_file }
4034
end
4135
end
42-
43-
action_class do
44-
def whyrun_supported?
45-
true
46-
end
47-
end

‎resources/install_noop.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
provides :nssm_install
22

3+
unified_mode true
4+
35
property :source, String, identity: true, name_property: true
46
property :sha256, String, required: true
57

@@ -8,9 +10,3 @@
810
action :install do
911
::Chef::Log.warn('NSSM service can only be installed on Windows platforms!')
1012
end
11-
12-
action_class do
13-
def whyrun_supported?
14-
true
15-
end
16-
end

‎resources/service.rb

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
# TODO: migrate to nssm_service with a breaking change notice
33
provides :nssm, platform: 'windows'
44

5+
unified_mode true
6+
57
property :servicename, String, name_property: true
68
property :program, String, required: true
79
property :args, String
810
property :parameters, Hash, default: lazy { ::Mash.new }
911
property :nssm_binary, [String, NilClass], default: lazy { ::NSSM.binary_path node }
10-
property :start, [TrueClass, FalseClass], default: true
12+
property :start, [true, false], default: true
1113
# TODO: add start as default action with a breaking change
1214
default_action :install
1315

@@ -96,9 +98,3 @@
9698
not_if { current_resource.nil? }
9799
end
98100
end
99-
100-
action_class do
101-
def whyrun_supported?
102-
true
103-
end
104-
end

‎resources/service_noop.rb

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
provides :nssm_service
22
provides :nssm # TODO: migrate to nssm_service with a breaking change notice
33

4+
unified_mode true
5+
46
property :servicename, String, identity: true, name_property: true
57
property :program, String, required: true
68
property :args, String
79
property :parameters, Hash, default: lazy { ::Mash.new }
8-
property :nssm_binary, [String, NilClass], default: nil
10+
property :nssm_binary, [String, NilClass]
911
# TODO: remove this
10-
property :start, [TrueClass, FalseClass], default: true
12+
property :start, [true, false], default: true
1113

1214
action :install do
1315
::Chef::Log.warn('NSSM service can only be installed on Windows platforms!')
@@ -28,9 +30,3 @@
2830
action :stop do
2931
::Chef::Log.warn('NSSM service can only be stopped on Windows platforms!')
3032
end
31-
32-
action_class do
33-
def whyrun_supported?
34-
true
35-
end
36-
end

‎spec/unit/default_spec.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,20 @@
2626
)
2727
end
2828

29+
it 'extracts nssm' do
30+
expect(chef_run).to extract_archive_file('extract nssm').with(
31+
path: "#{CACHE}/nssm-#{VERSION}.zip",
32+
destination: "#{CACHE}/nssm"
33+
)
34+
end
35+
2936
it 'installs nssm' do
3037
allow(::File).to receive(:exist?).and_call_original
31-
expect(::File).to receive(:exist?).with("#{CACHE}/nssm-#{VERSION}/nssm-#{VERSION}/win64/nssm.exe").and_return true
38+
expect(::File).to receive(:exist?).with("#{CACHE}/nssm/nssm-#{VERSION}/win64/nssm.exe").and_return true
3239

3340
expect(chef_run).to create_remote_file('install nssm').with(
3441
path: "C:\\tmp\\nssm-#{VERSION}.exe",
35-
source: "file:///#{CACHE}/nssm-#{VERSION}/nssm-#{VERSION}/win64/nssm.exe"
42+
source: "file:///#{CACHE}/nssm/nssm-#{VERSION}/win64/nssm.exe"
3643
)
3744
end
3845
end

0 commit comments

Comments
 (0)