chef 0.9.12 → 0.9.14.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/distro/arch/etc/conf.d/chef-client.conf +5 -0
  2. data/distro/arch/etc/conf.d/chef-server-webui.conf +10 -0
  3. data/distro/arch/etc/conf.d/chef-server.conf +10 -0
  4. data/distro/arch/etc/conf.d/chef-solr-indexer.conf +8 -0
  5. data/distro/arch/etc/conf.d/chef-solr.conf +8 -0
  6. data/distro/arch/etc/rc.d/chef-client +76 -0
  7. data/distro/arch/etc/rc.d/chef-server +82 -0
  8. data/distro/arch/etc/rc.d/chef-server-webui +82 -0
  9. data/distro/arch/etc/rc.d/chef-solr +82 -0
  10. data/distro/arch/etc/rc.d/chef-solr-indexer +82 -0
  11. data/distro/common/markdown/knife.mkd +34 -1
  12. data/distro/debian/etc/default/chef-solr +1 -0
  13. data/distro/debian/etc/init.d/chef-client +1 -1
  14. data/distro/debian/etc/init.d/chef-solr +39 -40
  15. data/distro/debian/etc/init.d/chef-solr-indexer +1 -1
  16. data/distro/redhat/etc/init.d/chef-client +1 -1
  17. data/lib/chef.rb +1 -0
  18. data/lib/chef/api_client.rb +1 -1
  19. data/lib/chef/application/agent.rb +1 -1
  20. data/lib/chef/application/client.rb +1 -1
  21. data/lib/chef/application/solo.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +2 -2
  23. data/lib/chef/cookbook/syntax_check.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +5 -1
  25. data/lib/chef/couchdb.rb +1 -1
  26. data/lib/chef/data_bag.rb +1 -1
  27. data/lib/chef/data_bag_item.rb +35 -9
  28. data/lib/chef/exceptions.rb +2 -0
  29. data/lib/chef/file_cache.rb +1 -1
  30. data/lib/chef/handler/json_file.rb +1 -1
  31. data/lib/chef/index_queue/amqp_client.rb +2 -2
  32. data/lib/chef/index_queue/consumer.rb +2 -2
  33. data/lib/chef/json.rb +52 -0
  34. data/lib/chef/knife.rb +6 -6
  35. data/lib/chef/knife/bluebox_images_list.rb +54 -0
  36. data/lib/chef/knife/bluebox_server_create.rb +157 -0
  37. data/lib/chef/knife/bluebox_server_delete.rb +63 -0
  38. data/lib/chef/knife/bluebox_server_list.rb +59 -0
  39. data/lib/chef/knife/bootstrap.rb +3 -1
  40. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  41. data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -2
  42. data/lib/chef/knife/bootstrap/fedora13-gems.erb +1 -1
  43. data/lib/chef/knife/client_bulk_delete.rb +1 -1
  44. data/lib/chef/knife/client_create.rb +1 -1
  45. data/lib/chef/knife/client_delete.rb +1 -1
  46. data/lib/chef/knife/client_edit.rb +1 -1
  47. data/lib/chef/knife/client_list.rb +1 -1
  48. data/lib/chef/knife/client_reregister.rb +1 -1
  49. data/lib/chef/knife/client_show.rb +1 -1
  50. data/lib/chef/knife/cookbook_create.rb +1 -1
  51. data/lib/chef/knife/cookbook_list.rb +1 -1
  52. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  53. data/lib/chef/knife/cookbook_show.rb +10 -18
  54. data/lib/chef/knife/cookbook_site_share.rb +1 -1
  55. data/lib/chef/knife/cookbook_site_vendor.rb +17 -11
  56. data/lib/chef/knife/ec2_instance_data.rb +1 -1
  57. data/lib/chef/knife/ec2_server_create.rb +8 -6
  58. data/lib/chef/knife/ec2_server_delete.rb +5 -8
  59. data/lib/chef/knife/ec2_server_list.rb +5 -4
  60. data/lib/chef/knife/exec.rb +1 -1
  61. data/lib/chef/knife/node_bulk_delete.rb +1 -1
  62. data/lib/chef/knife/node_create.rb +1 -1
  63. data/lib/chef/knife/node_delete.rb +1 -1
  64. data/lib/chef/knife/node_edit.rb +1 -1
  65. data/lib/chef/knife/node_from_file.rb +2 -2
  66. data/lib/chef/knife/node_list.rb +1 -1
  67. data/lib/chef/knife/node_run_list_add.rb +1 -1
  68. data/lib/chef/knife/node_run_list_remove.rb +1 -1
  69. data/lib/chef/knife/node_show.rb +1 -1
  70. data/lib/chef/knife/rackspace_server_create.rb +98 -70
  71. data/lib/chef/knife/rackspace_server_delete.rb +2 -2
  72. data/lib/chef/knife/rackspace_server_list.rb +2 -2
  73. data/lib/chef/knife/role_bulk_delete.rb +1 -1
  74. data/lib/chef/knife/role_create.rb +1 -1
  75. data/lib/chef/knife/role_delete.rb +1 -1
  76. data/lib/chef/knife/role_edit.rb +1 -1
  77. data/lib/chef/knife/role_from_file.rb +2 -2
  78. data/lib/chef/knife/role_list.rb +1 -1
  79. data/lib/chef/knife/role_show.rb +1 -1
  80. data/lib/chef/knife/slicehost_images_list.rb +2 -2
  81. data/lib/chef/knife/slicehost_server_create.rb +2 -2
  82. data/lib/chef/knife/slicehost_server_delete.rb +2 -2
  83. data/lib/chef/knife/slicehost_server_list.rb +2 -2
  84. data/lib/chef/knife/ssh.rb +36 -12
  85. data/lib/chef/knife/status.rb +1 -1
  86. data/lib/chef/knife/terremark_server_create.rb +1 -1
  87. data/lib/chef/knife/terremark_server_delete.rb +1 -1
  88. data/lib/chef/knife/terremark_server_list.rb +1 -1
  89. data/lib/chef/log.rb +31 -4
  90. data/lib/chef/mixin/command.rb +1 -1
  91. data/lib/chef/mixin/create_path.rb +1 -1
  92. data/lib/chef/mixin/recipe_definition_dsl_core.rb +1 -1
  93. data/lib/chef/monkey_patches/numeric.rb +7 -0
  94. data/lib/chef/node.rb +6 -8
  95. data/lib/chef/node/attribute.rb +24 -2
  96. data/lib/chef/openid_registration.rb +1 -1
  97. data/lib/chef/platform.rb +11 -0
  98. data/lib/chef/provider/breakpoint.rb +1 -1
  99. data/lib/chef/provider/cookbook_file.rb +1 -1
  100. data/lib/chef/provider/deploy/revision.rb +1 -1
  101. data/lib/chef/provider/deploy/timestamped.rb +1 -1
  102. data/lib/chef/provider/erl_call.rb +14 -2
  103. data/lib/chef/provider/git.rb +79 -55
  104. data/lib/chef/provider/group/pw.rb +1 -1
  105. data/lib/chef/provider/package/easy_install.rb +35 -13
  106. data/lib/chef/provider/service/debian.rb +65 -40
  107. data/lib/chef/provider/service/insserv.rb +52 -0
  108. data/lib/chef/provider/service/windows.rb +74 -57
  109. data/lib/chef/provider/subversion.rb +45 -10
  110. data/lib/chef/provider/user/pw.rb +1 -1
  111. data/lib/chef/providers.rb +1 -0
  112. data/lib/chef/resource/deploy_revision.rb +1 -1
  113. data/lib/chef/resource/easy_install_package.rb +16 -0
  114. data/lib/chef/resource/file.rb +8 -1
  115. data/lib/chef/resource_collection/stepable_iterator.rb +1 -1
  116. data/lib/chef/rest.rb +7 -7
  117. data/lib/chef/role.rb +2 -2
  118. data/lib/chef/run_status.rb +1 -1
  119. data/lib/chef/shef.rb +2 -2
  120. data/lib/chef/shef/ext.rb +2 -2
  121. data/lib/chef/shef/model_wrapper.rb +1 -1
  122. data/lib/chef/shef/shef_rest.rb +1 -1
  123. data/lib/chef/shef/shef_session.rb +13 -5
  124. data/lib/chef/tasks/chef_repo.rake +1 -1
  125. data/lib/chef/version.rb +1 -1
  126. data/lib/chef/webui_user.rb +1 -1
  127. metadata +329 -290
@@ -81,4 +81,4 @@ class Chef
81
81
  end
82
82
  end
83
83
  end
84
- end
84
+ end
@@ -34,16 +34,18 @@ class Chef
34
34
 
35
35
  begin
36
36
  # first check to see if we can import it
37
- output = shell_out!("python -c \"import #{name}\"").stderr
38
- unless output.include? "ImportError"
37
+ output = shell_out!("#{python_binary_path} -c \"import #{name}\"", :returns=>[0,1]).stderr
38
+ if output.include? "ImportError"
39
+ # then check to see if its on the path
40
+ output = shell_out!("#{python_binary_path} -c \"import sys; print sys.path\"", :returns=>[0,1]).stdout
41
+ if output.downcase.include? "#{name.downcase}"
42
+ check = true
43
+ end
44
+ else
39
45
  check = true
40
46
  end
41
47
  rescue
42
- # then check to see if its on the path
43
- output = shell_out!("python -c \"import sys; print sys.path\"").stdout
44
- if output.downcase.include? "#{name.downcase}"
45
- check = true
46
- end
48
+ # it's probably not installed
47
49
  end
48
50
 
49
51
  check
@@ -54,6 +56,16 @@ class Chef
54
56
  path ? path : 'easy_install'
55
57
  end
56
58
 
59
+ def python_binary_path
60
+ path = @new_resource.python_binary
61
+ path ? path : 'python'
62
+ end
63
+
64
+ def module_name
65
+ m = @new_resource.module_name
66
+ m ? m : @new_resource.name
67
+ end
68
+
57
69
  def load_current_resource
58
70
  @current_resource = Chef::Resource::Package.new(@new_resource.name)
59
71
  @current_resource.package_name(@new_resource.package_name)
@@ -61,20 +73,30 @@ class Chef
61
73
 
62
74
  # get the currently installed version if installed
63
75
  package_version = nil
64
- if install_check(@new_resource.package_name)
76
+ if install_check(module_name)
65
77
  begin
66
- output = shell_out!("python -c \"import #{@new_resource.package_name}; print #{@new_resource.package_name}.__version__\"").stdout
78
+ output = shell_out!("#{python_binary_path} -c \"import #{module_name}; print #{module_name}.__version__\"").stdout
67
79
  package_version = output.strip
68
80
  rescue
69
- output = shell_out!("python -c \"import #{@new_resource.package_name}; print #{@new_resource.package_name}.__path__\"").stdout
70
- output[/\S\S(.*)\/(.*)-(.*)-py(.*).egg\S/]
81
+ output = shell_out!("#{python_binary_path} -c \"import sys; print sys.path\"", :returns=>[0,1]).stdout
82
+
83
+ output_array = output.gsub(/[\[\]]/,'').split(/\s*,\s*/)
84
+ package_path = ""
85
+
86
+ output_array.each do |entry|
87
+ if entry.downcase.include?(@new_resource.package_name)
88
+ package_path = entry
89
+ end
90
+ end
91
+
92
+ package_path[/\S\S(.*)\/(.*)-(.*)-py(.*).egg\S/]
71
93
  package_version = $3
72
94
  end
73
95
  end
74
96
 
75
97
  if package_version == @new_resource.version
76
98
  Chef::Log.debug("#{@new_resource.package_name} at version #{@new_resource.version}")
77
- @current_resource.version(@new_resource.version)
99
+ @current_resource.version(@new_resource.version)
78
100
  else
79
101
  Chef::Log.debug("#{@new_resource.package_name} at version #{package_version}")
80
102
  @current_resource.version(package_version)
@@ -111,4 +133,4 @@ class Chef
111
133
  end
112
134
  end
113
135
  end
114
- end
136
+ end
@@ -24,81 +24,106 @@ class Chef
24
24
  class Provider
25
25
  class Service
26
26
  class Debian < Chef::Provider::Service::Init
27
- UPDATE_RC_D_ENABLED_MATCHES = /etc\/rc[\dS].d\/S|not installed/i
28
- UPDATE_RC_D_PRIORITIES = /etc\/rc([\dS]).d\/([SK])(\d\d)/i
27
+ UPDATE_RC_D_ENABLED_MATCHES = /\/rc[\dS].d\/S|not installed/i
28
+ UPDATE_RC_D_PRIORITIES = /\/rc([\dS]).d\/([SK])(\d\d)/i
29
29
 
30
30
  def load_current_resource
31
31
  super
32
-
33
- @current_resource.enabled(service_currently_enabled?)
34
- @current_resource
35
- end
36
32
 
37
- def enable_service()
38
- run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} defaults")
33
+ @current_resource.priority(get_priority)
34
+ @current_resource.enabled(service_currently_enabled?(@current_resource.priority))
35
+ @current_resource
39
36
  end
40
37
 
41
- def disable_service()
42
- run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
43
- end
44
-
45
38
  def assert_update_rcd_available
46
39
  unless ::File.exists? "/usr/sbin/update-rc.d"
47
40
  raise Chef::Exceptions::Service, "/usr/sbin/update-rc.d does not exist!"
48
41
  end
49
42
  end
50
-
51
- def service_currently_enabled?
43
+
44
+ def get_priority
52
45
  assert_update_rcd_available
46
+ priority = {}
53
47
 
54
48
  status = popen4("/usr/sbin/update-rc.d -n -f #{@current_resource.service_name} remove") do |pid, stdin, stdout, stderr|
55
- priority = {}
56
- enabled = false
57
49
 
58
- stdout.each_line do |line|
59
- if UPDATE_RC_D_PRIORITIES =~ line
60
- priority[$1] = [($2 == "S" ? :start : :stop), $3]
61
- end
62
- if line =~ UPDATE_RC_D_ENABLED_MATCHES
63
- enabled = true
50
+ [stdout, stderr].each do |iop|
51
+ iop.each_line do |line|
52
+ if UPDATE_RC_D_PRIORITIES =~ line
53
+ # priority[runlevel] = [ S|K, priority ]
54
+ # S = Start, K = Kill
55
+ # debian runlevels: 0 Halt, 1 Singleuser, 2 Multiuser, 3-5 == 2, 6 Reboot
56
+ priority[$1] = [($2 == "S" ? :start : :stop), $3]
57
+ end
58
+ if line =~ UPDATE_RC_D_ENABLED_MATCHES
59
+ enabled = true
60
+ end
64
61
  end
65
62
  end
66
- @current_resource.enabled enabled
67
- @current_resource.priority priority
68
- end
63
+ end
69
64
 
70
65
  unless status.exitstatus == 0
71
66
  raise Chef::Exceptions::Service, "/usr/sbin/update-rc.d -n -f #{@current_resource.service_name} failed - #{status.inspect}"
72
67
  end
73
- @current_resource.enabled
68
+ priority
74
69
  end
75
70
 
76
- def enable_service()
77
- # If we have a priority which is just a number, we have to
78
- # construct the actual priority object
71
+ def service_currently_enabled?(priority)
72
+ enabled = false
73
+
74
+ priority.each { |runlevel, arguments|
75
+ Chef::Log.debug("service[#{@current_resource.name}]: runlevel #{runlevel}, action #{arguments[0]}, priority #{arguments[1]}")
76
+
77
+ # if we are in a update-rc.d default startup runlevel && we start in this runlevel
78
+ if (2..5).include?(runlevel.to_i) && arguments[0] == :start
79
+ enabled = true
80
+ end
81
+ }
79
82
 
83
+ enabled
84
+ end
85
+
86
+ def enable_service()
80
87
  if @new_resource.priority.is_a? Integer
88
+ run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
81
89
  run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} defaults #{@new_resource.priority} #{100 - @new_resource.priority}")
82
90
  elsif @new_resource.priority.is_a? Hash
83
- args = ""
84
- @new_resource.priority.each do |level, o|
85
- action = o[0]
86
- priority = o[1]
87
- args += "#{action} #{priority} #{level} . "
88
- end
89
- run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} #{args}")
91
+ # we call the same command regardless of we're enabling or disabling
92
+ # users passing a Hash are responsible for setting their own start priorities
93
+ set_priority()
90
94
  else # No priority, go with update-rc.d defaults
95
+ run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
91
96
  run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} defaults")
92
97
  end
93
98
 
94
99
  end
95
100
 
96
101
  def disable_service()
97
- run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} disable")
98
- # @new_resource.priority({2 => [:stop, 80]})
99
- # enable_service
102
+ if @new_resource.priority.is_a? Integer
103
+ # Stop processes in reverse order of start using '100 - start_priority'
104
+ run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
105
+ run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} stop #{100 - @new_resource.priority} 2 3 4 5 .")
106
+ elsif @new_resource.priority.is_a? Hash
107
+ # we call the same command regardless of we're enabling or disabling
108
+ # users passing a Hash are responsible for setting their own stop priorities
109
+ set_priority()
110
+ else
111
+ # no priority, using '100 - 20 (update-rc.d default)' to stop in reverse order of start
112
+ run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
113
+ run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} stop 80 2 3 4 5 .")
114
+ end
115
+ end
116
+
117
+ def set_priority()
118
+ args = ""
119
+ @new_resource.priority.each do |level, o|
120
+ action = o[0]
121
+ priority = o[1]
122
+ args += "#{action} #{priority} #{level} . "
123
+ end
124
+ run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
125
+ run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} #{args}")
100
126
  end
101
-
102
127
  end
103
128
  end
104
129
  end
@@ -0,0 +1,52 @@
1
+ #
2
+ # Author:: Bryan McLellan <btm@loftninjas.org>
3
+ # Copyright:: Copyright (c) 2011 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/provider/service'
20
+ require 'chef/provider/service/init'
21
+ require 'chef/mixin/command'
22
+
23
+ class Chef
24
+ class Provider
25
+ class Service
26
+ class Insserv < Chef::Provider::Service::Init
27
+
28
+ def load_current_resource
29
+ super
30
+
31
+ # Look for a /etc/rc.*/SnnSERVICE link to signifiy that the service would be started in a runlevel
32
+ if Dir.glob("/etc/rc**/S*#{@current_resource.service_name}").empty?
33
+ @current_resource.enabled false
34
+ else
35
+ @current_resource.enabled true
36
+ end
37
+
38
+ @current_resource
39
+ end
40
+
41
+ def enable_service()
42
+ run_command(:command => "/sbin/insserv -r -f #{@new_resource.service_name}")
43
+ run_command(:command => "/sbin/insserv -d -f #{@new_resource.service_name}")
44
+ end
45
+
46
+ def disable_service()
47
+ run_command(:command => "/sbin/insserv -r -f #{@new_resource.service_name}")
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Nuo Yan <nuo@opscode.com>
3
+ # Author:: Bryan McLellan <btm@loftninjas.org>
3
4
  # Copyright:: Copyright (c) 2010 Opscode, Inc
4
5
  # License:: Apache License, Version 2.0
5
6
  #
@@ -16,68 +17,86 @@
16
17
  # limitations under the License.
17
18
  #
18
19
 
19
- require 'chef/provider/service/init'
20
+ # pick up popen4 from chef/mixin/command/windows
21
+ require 'chef/mixin/command'
22
+ require 'chef/provider/service/simple'
20
23
 
21
- class Chef::Provider::Service::Windows < Chef::Provider::Service::Init
24
+ class Chef::Provider::Service::Windows < Chef::Provider::Service::Simple
22
25
 
23
26
  def initialize(new_resource, run_context)
24
27
  super
25
28
  @init_command = "sc"
26
29
  end
27
30
 
31
+ def io_popen(command)
32
+ io = IO.popen(command)
33
+ entries = io.readlines
34
+ io.close
35
+ entries
36
+ end
37
+
28
38
  def load_current_resource
29
39
  @current_resource = Chef::Resource::Service.new(@new_resource.name)
30
40
  @current_resource.service_name(@new_resource.service_name)
31
- status = IO.popen("#{@init_command} query #{@new_resource.service_name}").entries
32
- raise Chef::Exceptions::Exec, "Service #{@new_resource.service_name} does not exist.\n#{status.join}\n" if status[0].include?("FAILED 1060")
33
-
34
41
  begin
35
- started = status[3].include?("4")
36
- @current_resource.running started
42
+ # Check if service is running
43
+ status = popen4("#{@init_command} query #{@new_resource.service_name}") do |pid, stdin, stdout, stderr|
44
+ stdout.each_line do |line|
45
+ raise Chef::Exceptions::Service, "Service #{@new_resource.service_name} does not exist.\n#{stdout}\n" if line =~ /FAILED 1060/
46
+ @current_resource.running true if line =~/RUNNING/
47
+ end
48
+ end
37
49
 
38
- start_type = IO.popen("#{@init_command} qc #{@new_resource.service_name}").entries[4]
39
- @current_resource.enabled(start_type.include?('2') || start_type.include?('3') ? true : false)
50
+ # Check if service is enabled
51
+ status = popen4("#{@init_command} qc #{@new_resource.service_name}") do |pid, stdin, stdout, stderr|
52
+ stdout.each_line do |line|
53
+ raise Chef::Exceptions::Service, "Service #{@new_resource.service_name} does not exist.\n#{stdout}\n" if line =~ /FAILED 1060/
54
+ @current_resource.enabled true if line =~/AUTO_START/
55
+ end
56
+ end
40
57
 
41
58
  Chef::Log.debug "#{@new_resource}: running: #{@current_resource.running}"
42
- rescue StandardError
43
- raise Chef::Exceptions::Exec
44
- rescue Chef::Exceptions::Exec
45
- Chef::Log.debug "Failed to determine the current status of the service, assuming it is not running"
46
- @current_resource.running false
47
- nil
59
+ rescue Exception => e
60
+ raise Chef::Exceptions::Service, "Exception determining state of service #{@new_resource.service_name}: #{e.message}"
48
61
  end
49
62
  @current_resource
50
63
  end
51
64
 
52
65
  def start_service
53
66
  begin
54
- result = if @new_resource.start_command
55
- Chef::Log.debug "starting service using the given start_command"
56
- IO.popen(@new_resource.start_command).readlines
57
- else
58
- IO.popen("#{@init_command} start #{@new_resource.service_name}").readlines
59
- end
60
- Chef::Log.debug result.join
61
- result[3].include?('4') || result.include?('2') ? true : false
62
- rescue
63
- Chef::Log.debug "Failed to start service #{@new_resource.service_name}"
64
- false
67
+ if @new_resource.start_command
68
+ popen4(@new_resource.start_command) do |pid, stdin, stdout, stderr|
69
+ Chef::Log.debug stdout.readlines
70
+ end
71
+ else
72
+ popen4("#{@init_command} start #{@new_resource.service_name}") do |pid, stdin, stdout, stderr|
73
+ output = stdout.readlines
74
+ Chef::Log.debug output.join
75
+ output.join =~ /RUNNING/ || output.join =~ /START_PENDING/ ? true : false
76
+ end
77
+ end
78
+ rescue Exception => e
79
+ raise Chef::Exceptions::Service, "Failed to start service #{@new_resource.service_name}: #{e.message}"
65
80
  end
66
81
  end
67
82
 
68
83
  def stop_service
69
84
  begin
70
- Chef::Log.debug "stopping service using the given stop_command"
71
- result = if @new_resource.stop_command
72
- IO.popen(@new_resource.stop_command).readlines
73
- else
74
- IO.popen("#{@init_command} stop #{@new_resource.service_name}").readlines
75
- end
76
- Chef::Log.debug result.join
77
- result[3].include?('1')
78
- rescue
79
- Chef::Log.debug "Failed to stop service #{@new_resource.service_name}"
80
- false
85
+ if @new_resource.stop_command
86
+ Chef::Log.debug "stopping service using the given stop_command"
87
+ popen4(@new_resource.stop_command) do |pid, stdin, stdout, stderr|
88
+ Chef::Log.debug stdout.readlines
89
+ end
90
+ else
91
+ popen4("#{@init_command} stop #{@new_resource.service_name}") do |pid, stdin, stdout, stderr|
92
+ output = stdout.readlines
93
+ Chef::Log.debug output.join
94
+ raise Chef::Exceptions::Service, "Service #{@new_resource.service_name} has dependencies and cannot be stopped.\n" if output.join =~ /FAILED 1051/
95
+ output.join =~ /1/
96
+ end
97
+ end
98
+ rescue Exception => e
99
+ raise Chef::Exceptions::Service, "Failed to start service #{@new_resource.service_name}: #{e.message}"
81
100
  end
82
101
  end
83
102
 
@@ -85,38 +104,36 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service::Init
85
104
  begin
86
105
  if @new_resource.restart_command
87
106
  Chef::Log.debug "restarting service using the given restart_command"
88
- result = IO.popen(@new_resource.restart_command).readlines
89
- Chef::Log.debug result.join
107
+ popen4(@new_resource.restart_command) do |pid, stdin, stdout, stderr|
108
+ Chef::Log.debug stdout.readlines
109
+ end
90
110
  else
91
- Chef::Log.debug IO.popen("#{@init_command} stop #{@new_resource.service_name}").readlines.join
111
+ stop_service
92
112
  sleep 1
93
- result = IO.popen("#{@init_command} start #{@new_resource.service_name}").readlines
94
- Chef::Log.debug result.join
113
+ start_service
95
114
  end
96
- result[3].include?('4') || result.include?('2')
97
- rescue
98
- Chef::Log.debug "Failed to restart service #{@new_resource.service_name}"
99
- false
115
+ rescue Exception => e
116
+ raise Chef::Exceptions::Service, "Failed to start service #{@new_resource.service_name}: #{e.message}"
100
117
  end
101
118
  end
102
119
 
103
120
  def enable_service()
104
121
  begin
105
- Chef::Log.debug result = IO.popen("#{@init_command} config #{@new_resource.service_name} start= #{determine_startup_type}").readlines.join
106
- result.include?('SUCCESS')
107
- rescue
108
- Chef::Log.debug "Failed to enable service #{@new_resource.service_name}"
109
- false
122
+ popen4("#{@init_command} config #{@new_resource.service_name} start= #{determine_startup_type}") do |pid, stdin, stdout, stderr|
123
+ stdout.readlines.join =~ /SUCCESS/
124
+ end
125
+ rescue Exception => e
126
+ raise Chef::Exceptions::Service, "Failed to start service #{@new_resource.service_name}: #{e.message}"
110
127
  end
111
128
  end
112
129
 
113
130
  def disable_service()
114
131
  begin
115
- Chef::Log.debug result = IO.popen("#{@init_command} config #{@new_resource.service_name} start= disabled").readlines.join
116
- result.include?('SUCCESS')
117
- rescue
118
- Chef::Log.debug "Failed to disable service #{@new_resource.service_name}"
119
- false
132
+ popen4("#{@init_command} config #{@new_resource.service_name} start= disabled") do |pid, stdin, stdout, stderr|
133
+ stdout.readlines.join =~ /SUCCESS/
134
+ end
135
+ rescue Exception => e
136
+ raise Chef::Exceptions::Service, "Failed to start service #{@new_resource.service_name}: #{e.message}"
120
137
  end
121
138
  end
122
139
 
@@ -126,4 +143,4 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service::Init
126
143
  {:automatic => 'auto', :mannual => 'demand'}[@new_resource.startup_type]
127
144
  end
128
145
 
129
- end
146
+ end