Skip to content

Commit

Permalink
Add parameters support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Hoer committed Sep 29, 2014
1 parent 6ff0e2e commit 052ad0f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions providers/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion resources/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions spec/unit/install_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/cookbooks/nssm_test/recipes/install_service.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 052ad0f

Please sign in to comment.