Skip to content

Commit

Permalink
Add ability to specify dependencies in chef-service-manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Null Cating-Subramanian committed Jul 24, 2015
1 parent 283301d commit ca8a8bd
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [pr#3666](https://github.com/chef/chef/pull/3666) Support SNI in `knife ssl check`.
* [pr#3667](https://github.com/chef/chef/pull/3667) Change chef service to start as 'Automatic delayed start'.
* [pr#3683](https://github.com/chef/chef/pull/3683) Correct Windows reboot command to delay in minutes, per the property.
* [pr#3698](https://github.com/chef/chef/pull/3698) Add ability to specify dependencies in chef-service-manager.

## 12.4.1

Expand Down
4 changes: 2 additions & 2 deletions bin/chef-service-manager
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ if Chef::Platform.windows?
:service_display_name => "Chef Client Service",
:service_description => "Runs Chef Client on regular, configurable intervals.",
:service_file_path => File.expand_path(File.join(File.dirname(__FILE__), '../../../../bin/chef-windows-service')),
:delayed_start => true
:delayed_start => true,
:dependencies => ['Winmgmt']
}
Chef::Application::WindowsServiceManager.new(chef_client_service).run
else
puts "chef-service-manager is only available on Windows platforms."
end

16 changes: 9 additions & 7 deletions lib/chef/application/windows_service_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def initialize(service_options)
@service_start_name = service_options[:run_as_user]
@password = service_options[:run_as_password]
@delayed_start = service_options[:delayed_start]
@dependencies = service_options[:dependencies]
end

def run(params = ARGV)
Expand All @@ -114,16 +115,17 @@ def run(params = ARGV)
cmd = "\"#{ruby}\" \"#{@service_file_path}\" #{opts}".gsub(File::SEPARATOR, File::ALT_SEPARATOR)

::Win32::Service.new(
:service_name => @service_name,
:display_name => @service_display_name,
:description => @service_description,
:service_name => @service_name,
:display_name => @service_display_name,
:description => @service_description,
# Prior to 0.8.5, win32-service creates interactive services by default,
# and we don't want that, so we need to override the service type.
:service_type => ::Win32::Service::SERVICE_WIN32_OWN_PROCESS,
:start_type => ::Win32::Service::SERVICE_AUTO_START,
:binary_path_name => cmd,
:service_type => ::Win32::Service::SERVICE_WIN32_OWN_PROCESS,
:start_type => ::Win32::Service::SERVICE_AUTO_START,
:binary_path_name => cmd,
:service_start_name => @service_start_name,
:password => @password,
:password => @password,
:dependencies => @dependencies
)
::Win32::Service.configure(
:service_name => @service_name,
Expand Down
5 changes: 1 addition & 4 deletions lib/chef/platform/query_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ def windows?
end

def windows_server_2003?
# WMI startup shouldn't be performed unless we're on Windows.
return false unless windows?
require 'wmi-lite/wmi'

# CHEF-4888: Work around ruby #2618, expected to be fixed in Ruby 2.1.0
# https://github.com/ruby/ruby/commit/588504b20f5cc880ad51827b93e571e32446e5db
# https://github.com/ruby/ruby/commit/27ed294c7134c0de582007af3c915a635a6506cd

wmi = WmiLite::Wmi.new
host = wmi.first_of('Win32_OperatingSystem')
is_server_2003 = (host['version'] && host['version'].start_with?("5.2"))
Expand Down
4 changes: 0 additions & 4 deletions lib/chef/win32/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ def get_version
# WMI always returns the truth. See article at
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx

# CHEF-4888: Work around ruby #2618, expected to be fixed in Ruby 2.1.0
# https://github.com/ruby/ruby/commit/588504b20f5cc880ad51827b93e571e32446e5db
# https://github.com/ruby/ruby/commit/27ed294c7134c0de582007af3c915a635a6506cd

wmi = WmiLite::Wmi.new
os_info = wmi.first_of('Win32_OperatingSystem')
os_version = os_info['version']
Expand Down

0 comments on commit ca8a8bd

Please sign in to comment.