diff --git a/.travis.yml b/.travis.yml index 2575b91..280a208 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: ruby rvm: - - "2.0.0" + - "1.9.3" diff --git a/README.md b/README.md index 38acaf2..d0623ac 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,12 @@ [![Build Status](https://travis-ci.org/dhoer/chef-nssm.svg)](https://travis-ci.org/dhoer/chef-nssm) This cookbook installs the Non-Sucking Service Manager (http://nssm.cc), and exposes resources to `install` and `remove` Windows services. -Read [TLDR](https://github.com/dhoer/chef-nssm/blob/master/TLDR.md) for more details about usage, chefspec matchers, getting help and contributing. +Read [TLDR](https://github.com/dhoer/chef-nssm/blob/master/TLDR.md) for more details about usage, chefspec matchers, getting help, and contributing. ## Requirements +Chef 11.14.2 and Ruby 1.9.3 or higher. + ### Platform - Windows Server 2012 R2 diff --git a/TLDR.md b/TLDR.md index 7f0f2d8..219edf6 100644 --- a/TLDR.md +++ b/TLDR.md @@ -4,22 +4,24 @@ Advanced usage of NSSM. -### Examples +### Arguments with Spaces -When dealing with an argument that contain spaces, add triple double quotes `"""` around it: +Having spaces in `servicename` and `program` attributes is not a problem, but spaces in an argument is a different matter. + +When dealing with an argument containing spaces, add [3 double quotes](https://stackoverflow.com/questions/7760545/cmd-escape-double-quotes-in-parameter/15262019#15262019?s=62228804c3f84fceb873ee30dd784161) `"""` around it: nssm 'service name' do - program 'C:\\Windows\\System32\\java.exe' + program 'C:\Program Files\Java\jdk1.7.0_67\bin\java.exe' args '-jar """C:/path/with spaces to/my-executable.jar"""' action :install end -When dealing with an arguments that require interpolation and handling of spaces, then encapsulate the entire args using `%Q{}` notation and use `"""` around the arguments containing spaces: +When dealing with arguments requiring [interpolation](http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#Interpolation) and contain an argument with spaces, then encapsulate `args` using `%{}` notation and use `"""` around arguments with spaces: - my_path_with_spaces = 'C:/path/with spaces to/my-executable.jar + my_path_with_spaces = 'C:/path/with spaces to/my-executable.jar' nssm 'service name' do - program 'C:\\Windows\\System32\\java.exe' - args %Q{-jar """#{my_path_with_spaces}"""} + program 'C:\Program Files\Java\jdk1.7.0_67\bin\java.exe' + args %{-jar """#{my_path_with_spaces}"""} action :install end diff --git a/providers/default.rb b/providers/default.rb index 2258f83..05cb86d 100644 --- a/providers/default.rb +++ b/providers/default.rb @@ -16,7 +16,7 @@ def service_installed?(servicename) batch "Install #{new_resource.servicename} service" do code <<-EOH - nssm install "#{new_resource.servicename}" #{new_resource.program} #{new_resource.args} + nssm install "#{new_resource.servicename}" "#{new_resource.program}" #{new_resource.args} EOH not_if { service_installed } end diff --git a/spec/unit/install_service_spec.rb b/spec/unit/install_service_spec.rb index 9d1b31f..aec113b 100644 --- a/spec/unit/install_service_spec.rb +++ b/spec/unit/install_service_spec.rb @@ -21,7 +21,7 @@ it 'executes batch command to install service' do expect(chef_run).to run_batch('Install service name service').with( - code: %r{nssm install "service name" C:\\Windows\\System32\\java.exe -jar C:/path/to/my-executable.jar} + code: %r{nssm install "service name" "C:\\Windows\\System32\\java.exe" -jar C:/path/to/my-executable.jar} ) end