Skip to content
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

[COOK-1863] Change default service style on Windows to windows_service if Chef >= 11.6 #110

Closed
wants to merge 12 commits into from
Closed
2 changes: 1 addition & 1 deletion attributes/default.rb
Expand Up @@ -106,7 +106,7 @@
default["chef_client"]["method_dir"] = "/opt/local/lib/svc/method"
default["chef_client"]["bin_dir"] = "/opt/local/bin"
when "windows"
default["chef_client"]["init_style"] = "winsw"
default["chef_client"]["init_style"] = "windows"
default["chef_client"]["conf_dir"] = "C:/chef"
default["chef_client"]["run_path"] = "#{node["chef_client"]["conf_dir"]}/run"
default["chef_client"]["cache_path"] = "#{node["chef_client"]["conf_dir"]}/cache"
Expand Down
1 change: 1 addition & 0 deletions recipes/service.rb
Expand Up @@ -31,6 +31,7 @@
'runit',
'smf',
'upstart',
'windows',
'winsw'
]
init_style = node["chef_client"]["init_style"]
Expand Down
40 changes: 40 additions & 0 deletions recipes/windows_service.rb
@@ -0,0 +1,40 @@
#
# Cookbook Name:: chef-client
# Recipe:: windows_service
#
# Author:: Julian Dunn (<jdunn@opscode.com>)
#
# Copyright 2013, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

class ::Chef::Recipe
include ::Opscode::ChefClient::Helpers
end

# libraries/helpers.rb method to DRY directory creation resources
create_directories

# Will also avoid touching any winsw service if it exists
execute "register-chef-service" do
command "chef-service-manager -a install"
only_if { WMI::Win32_Service.find(:first, :conditions => {:name => 'chef-client'}).nil? }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an option where users can specify a different name for the chef-service other than chef-client ?

We should make sure this condition works for winsw + chef-service-manager style installed services.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a requirement? Given that we've assumed this naming up to now, in both the chef-client cookbook and what the MSI calls it on Windows if you install the service component, I'm a bit loath to change it, or to add that functionality. The code becomes very complicated if we have to account for this?

# Previous versions of Chef (< 11.6.x) had a windows_service library but no manager.
# However, they were also broken, so only try this on versions that have the manager
only_if "chef-service-manager -v"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking the version I would execute "chef-service-manager" and assume that we're on a good version if it executes. If it's not there exception will be thrown and we can fall back to using winsw.

If I was doing this based on version I would check the version as such:

only_if do
::Chef::VERSION <= "11.6."

More logic to make the version check.

end

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I couldn't see the fallback logic to winsw style service installation.

end

service "chef-client" do
action [:enable, :start]
end