diff --git a/providers/default.rb b/providers/default.rb index 05cb86d..6626084 100644 --- a/providers/default.rb +++ b/providers/default.rb @@ -21,6 +21,14 @@ def service_installed?(servicename) not_if { service_installed } end + new_resource.params.map do |k, v| + batch "Set parameter #{k} #{v}" do + code <<-EOH + nssm set "#{new_resource.servicename}" #{k} #{v} + EOH + end + end unless service_installed + if new_resource.start service new_resource.servicename do action [:start] diff --git a/resources/default.rb b/resources/default.rb index dfe9b2b..d3e4304 100644 --- a/resources/default.rb +++ b/resources/default.rb @@ -4,4 +4,5 @@ attribute :servicename, name_attribute: true attribute :program, kind_of: String, required: true attribute :args, kind_of: String -attribute :start, kind_of: [TrueClass, FalseClass], default: true +attribute :params, kind_of: Hash, default: {} +attribute :start, kind_of: [TrueClass, FalseClass], default: true diff --git a/spec/unit/install_service_spec.rb b/spec/unit/install_service_spec.rb index aec113b..69e4403 100644 --- a/spec/unit/install_service_spec.rb +++ b/spec/unit/install_service_spec.rb @@ -25,6 +25,30 @@ ) end + it 'sets start directory parameters' do + expect(chef_run).to run_batch('Set parameter AppDirectory C:/path/to').with( + code: %r{nssm set "service name" AppDirectory C:/path/to} + ) + end + + it 'sets service parameters' do + expect(chef_run).to run_batch('Set parameter AppStdout C:/path/to/log/service.log').with( + code: %r{nssm set "service name" AppStdout C:/path/to/log/service.log} + ) + end + + it 'sets service parameters' do + expect(chef_run).to run_batch('Set parameter AppStderr C:/path/to/log/error.log').with( + code: %r{nssm set "service name" AppStderr C:/path/to/log/error.log} + ) + end + + it 'sets service parameters' do + expect(chef_run).to run_batch('Set parameter AppRotateFiles 1').with( + code: /nssm set "service name" AppRotateFiles 1/ + ) + end + it 'starts service' do expect(chef_run).to start_service('service name') end diff --git a/test/fixtures/cookbooks/nssm_test/recipes/install_service.rb b/test/fixtures/cookbooks/nssm_test/recipes/install_service.rb index 811d764..b199e42 100644 --- a/test/fixtures/cookbooks/nssm_test/recipes/install_service.rb +++ b/test/fixtures/cookbooks/nssm_test/recipes/install_service.rb @@ -1,5 +1,11 @@ nssm 'service name' do program 'C:\\Windows\\System32\\java.exe' args '-jar C:/path/to/my-executable.jar' + params( + AppDirectory: 'C:/path/to', + AppStdout: 'C:/path/to/log/service.log', + AppStderr: 'C:/path/to/log/error.log', + AppRotateFiles: 1 + ) action :install end