-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor nssm resource #21
Refactor nssm resource #21
Conversation
This has been done for install_if_missing but not for the install action. This could be considered as a 'breaking change'. But it fixes a bit the behavior following criteo-cookbooks#7.
Instead of performing a adhoc WIN32OLE WMI query, use a gem written for that. This gem is already packaged with chef.
This requires nssm > 2.24
Recent version of nssm now better handle command line parameters. Passing arguments properly quoted is easier. This commit quotes & escape parameters in a way that the dump output is the same as the input. It helps for idempotency and ease usage of the resource. No need to triple quotes arguments :) But this is a breaking change because it changes the public interface of this resource, even if the behavior was already broken following last nssm bump.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall. I have not used the new resources syntax, so I had to understand what that was. The build on appveyor is failing do to a food critic saying a resource attribute is incorrect. The build will need to pass before I can merge it. Thanks for looking at this and getting it updated!
Gemfile
Outdated
@@ -4,7 +4,7 @@ source 'https://rubygems.org' | |||
|
|||
gem 'berkshelf' | |||
gem 'chef', '>= 12.7' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the Chef version be bumped based on Chefspec note:
ChefSpec requires Ruby 2.2 or later and Chef 12.14.89 or later!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes maybe we should bump chef in the Gemfile.
@@ -0,0 +1,96 @@ | |||
provides :nssm_service, platform: 'windows' | |||
# TODO: migrate to nssm_service with a breaking change notice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a major bump in version v4.0.0 be enough to signal breaking change, so is nssm_service is not really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think a v4.0.0 would be great, but currently I think my PR is not enough. Due to the way nssm binary is installed upgrade is not possible when a service is currently running.
In addition, the implementation I made for the load_current_value
does not work with older version of nssm
, another blocking point for the upgrade.
The nssm_service
would be great if we start having a resource for nssm_install
for instance.
I really think we should migrate the install
recipe into a resource, to enhance install/upgrade scenarii and allow people to subscribe to that kind of event.
|
||
#### Attribute Parameters | ||
|
||
- `servicename` - Name attribute. The name of the Windows service. | ||
- `program` - The program to be run as a service. | ||
- `args` - String of arguments for the program. Optional | ||
- `parameters` - Hash of key value pairs where key represents associated registry entry. Optional | ||
- `start` - Start service after installing. Default` - true | ||
- `start` - Start service after installing. Default - true | ||
- `nssm_binary` - Path to nssm binary. Default - `node['nssm']['install_location']\nssm.exe` | ||
|
||
## ChefSpec Matchers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section can go
resources/service.rb
Outdated
property :args, kind_of: String | ||
property :parameters, kind_of: Hash, default: lazy { ::Mash.new } | ||
property :nssm_binary, kind_of: String, default: lazy { "#{node['nssm']['install_location']}\\nssm.exe" } | ||
# TODO: migrate this to :start action with a breaking change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these just be removed if we do a major rev?
end | ||
|
||
ChefSpec.define_matcher :nssm | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool, didn't know you no longer needed matchers 👍
Resource can now be used via 'nssm' or 'nssm_service'. On windows it works the same. On other platforms it just logs warnings.
Chefspec autogenerate matchers. Also bump chef in Gemfile to match Chefspec 7.1 requirements.
NSSM commands were build by manual string concatenation. Foodcritic was unhappy when this was done inside an execute resource. Refactor the parameter_helper into nssm library with higher level methods.
Use win32-service to determine whether the service exist or not. Then if the `dump` command exist, use it to retrieve all settings at once. This allow backward compatibility with older version of nssm, but idempotency won't be perfect, settings will be set at every run.
8db4688
to
95df8d0
Compare
This allow nssm upgrade scenario. Each nssm service is bound to a specific version of nssm. If you decide to bump nssm, this'll update the service.
@dhoer I managed to get green CI :D I'm creating smaller reviews for different stuffs. |
Wow quick merge, thanks! |
Getting the following error: Do you have time to look at this? |
This is related to #22, I was looking at it but your merged it before I managed to get my test OK :D I'll try again ;) |
Following last nssm bump with the cookbook v3.0.1 the escaping behavior changed and broke contingent cookbooks. It also added extra execution time to check parameters values.
Non goals
This PR does not aim to be backward compatible.
Main changes
"""
for parameters with spacesload_current_value
usingnssm dump
nssm >= 2.24.94
for thenssm dump
commandstart
&stop
actions to manipulate the serviceThe README and tests have been updated accordingly. I did many commits to help see how I came to the current result.
Let me kow if you have any question, remark or feedback.
Cc. @aboten