chef 12.0.0.alpha.1 → 12.0.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef/application.rb +8 -1
  3. data/lib/chef/application/apply.rb +4 -0
  4. data/lib/chef/application/client.rb +7 -7
  5. data/lib/chef/application/solo.rb +21 -13
  6. data/lib/chef/chef_fs/chef_fs_data_store.rb +60 -6
  7. data/lib/chef/chef_fs/config.rb +78 -4
  8. data/lib/chef/chef_fs/data_handler/acl_data_handler.rb +2 -2
  9. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
  10. data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
  11. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  13. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +76 -2
  14. data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
  15. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
  16. data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
  17. data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +30 -0
  18. data/lib/chef/chef_fs/data_handler/organization_invites_data_handler.rb +17 -0
  19. data/lib/chef/chef_fs/data_handler/organization_members_data_handler.rb +17 -0
  20. data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
  21. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +2 -1
  22. data/lib/chef/chef_fs/file_system.rb +0 -1
  23. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  24. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +1 -1
  25. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +5 -1
  26. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +73 -13
  27. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +44 -5
  28. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +1 -1
  29. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -3
  30. data/lib/chef/chef_fs/file_system/org_entry.rb +34 -0
  31. data/lib/chef/chef_fs/file_system/organization_invites_entry.rb +58 -0
  32. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +57 -0
  33. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +13 -4
  34. data/lib/chef/chef_fs/knife.rb +1 -1
  35. data/lib/chef/client.rb +8 -2
  36. data/lib/chef/config.rb +75 -57
  37. data/lib/chef/config_fetcher.rb +6 -21
  38. data/lib/chef/dsl/data_query.rb +48 -3
  39. data/lib/chef/dsl/platform_introspection.rb +42 -0
  40. data/lib/chef/dsl/reboot_pending.rb +6 -3
  41. data/lib/chef/encrypted_data_bag_item.rb +1 -1
  42. data/lib/chef/encrypted_data_bag_item/encryptor.rb +12 -0
  43. data/lib/chef/exceptions.rb +2 -0
  44. data/lib/chef/http/basic_client.rb +14 -0
  45. data/lib/chef/http/json_output.rb +7 -2
  46. data/lib/chef/knife.rb +36 -121
  47. data/lib/chef/knife/bootstrap.rb +68 -54
  48. data/lib/chef/knife/bootstrap/archlinux-gems.erb +6 -1
  49. data/lib/chef/knife/bootstrap/chef-aix.erb +5 -0
  50. data/lib/chef/knife/bootstrap/chef-full.erb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +70 -29
  52. data/lib/chef/knife/search.rb +56 -12
  53. data/lib/chef/knife/serve.rb +1 -1
  54. data/lib/chef/local_mode.rb +10 -4
  55. data/lib/chef/mixin/deep_merge.rb +6 -3
  56. data/lib/chef/mixin/shell_out.rb +33 -17
  57. data/lib/chef/null_logger.rb +72 -0
  58. data/lib/chef/platform.rb +2 -1
  59. data/lib/chef/platform/provider_mapping.rb +1 -1
  60. data/lib/chef/platform/rebooter.rb +54 -0
  61. data/lib/chef/provider/ifconfig.rb +15 -16
  62. data/lib/chef/provider/link.rb +1 -1
  63. data/lib/chef/provider/mount/mount.rb +1 -1
  64. data/lib/chef/provider/mount/solaris.rb +102 -64
  65. data/lib/chef/provider/package/aix.rb +4 -12
  66. data/lib/chef/provider/package/ips.rb +8 -12
  67. data/lib/chef/provider/package/macports.rb +4 -12
  68. data/lib/chef/provider/package/pacman.rb +2 -6
  69. data/lib/chef/provider/package/portage.rb +2 -6
  70. data/lib/chef/provider/package/rpm.rb +4 -12
  71. data/lib/chef/provider/package/solaris.rb +4 -12
  72. data/lib/chef/provider/reboot.rb +69 -0
  73. data/lib/chef/provider/service/debian.rb +10 -10
  74. data/lib/chef/provider/service/freebsd.rb +89 -73
  75. data/lib/chef/provider/service/gentoo.rb +2 -2
  76. data/lib/chef/provider/service/init.rb +6 -4
  77. data/lib/chef/provider/service/insserv.rb +3 -3
  78. data/lib/chef/provider/service/macosx.rb +2 -2
  79. data/lib/chef/provider/service/simple.rb +6 -4
  80. data/lib/chef/provider/service/solaris.rb +1 -1
  81. data/lib/chef/provider/service/systemd.rb +9 -9
  82. data/lib/chef/provider/service/upstart.rb +6 -6
  83. data/lib/chef/provider/subversion.rb +6 -6
  84. data/lib/chef/provider/user/dscl.rb +32 -28
  85. data/lib/chef/provider/user/windows.rb +6 -6
  86. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  87. data/lib/chef/providers.rb +1 -0
  88. data/lib/chef/recipe.rb +0 -1
  89. data/lib/chef/resource.rb +3 -5
  90. data/lib/chef/resource/mount.rb +9 -0
  91. data/lib/chef/resource/reboot.rb +48 -0
  92. data/lib/chef/resources.rb +1 -0
  93. data/lib/chef/run_context.rb +25 -0
  94. data/lib/chef/search/query.rb +122 -14
  95. data/lib/chef/util/path_helper.rb +54 -6
  96. data/lib/chef/util/windows/net_user.rb +4 -1
  97. data/lib/chef/version.rb +1 -1
  98. data/lib/chef/win32/api/file.rb +1 -5
  99. data/lib/chef/win32/api/net.rb +1 -0
  100. data/lib/chef/workstation_config_loader.rb +177 -0
  101. data/spec/functional/http/simple_spec.rb +57 -1
  102. data/spec/functional/mixin/shell_out_spec.rb +2 -2
  103. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +51 -0
  104. data/spec/functional/rebooter_spec.rb +105 -0
  105. data/spec/functional/resource/deploy_revision_spec.rb +0 -4
  106. data/spec/functional/resource/file_spec.rb +26 -3
  107. data/spec/functional/resource/group_spec.rb +5 -3
  108. data/spec/functional/resource/link_spec.rb +16 -16
  109. data/spec/functional/resource/reboot_spec.rb +103 -0
  110. data/spec/integration/client/client_spec.rb +4 -8
  111. data/spec/integration/client/ipv6_spec.rb +1 -1
  112. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -2
  113. data/spec/integration/knife/delete_spec.rb +39 -0
  114. data/spec/integration/knife/deps_spec.rb +30 -20
  115. data/spec/integration/knife/download_spec.rb +77 -1
  116. data/spec/integration/knife/list_spec.rb +221 -0
  117. data/spec/integration/knife/raw_spec.rb +1 -1
  118. data/spec/integration/knife/show_spec.rb +2 -2
  119. data/spec/integration/knife/upload_spec.rb +154 -1
  120. data/spec/support/pedant/run_pedant.rb +0 -1
  121. data/spec/support/shared/functional/http.rb +8 -1
  122. data/spec/support/shared/integration/integration_helper.rb +11 -19
  123. data/spec/support/shared/unit/platform_introspector.rb +22 -0
  124. data/spec/unit/application/apply.rb +11 -1
  125. data/spec/unit/application/solo_spec.rb +19 -3
  126. data/spec/unit/chef_fs/config_spec.rb +58 -0
  127. data/spec/unit/config_fetcher_spec.rb +1 -3
  128. data/spec/unit/config_spec.rb +247 -220
  129. data/spec/unit/dsl/data_query_spec.rb +165 -23
  130. data/spec/unit/dsl/reboot_pending_spec.rb +1 -7
  131. data/spec/unit/encrypted_data_bag_item_spec.rb +1 -1
  132. data/spec/unit/knife/bootstrap_spec.rb +354 -182
  133. data/spec/unit/knife/core/bootstrap_context_spec.rb +67 -30
  134. data/spec/unit/knife_spec.rb +3 -30
  135. data/spec/unit/mixin/deep_merge_spec.rb +14 -0
  136. data/spec/unit/mixin/shell_out_spec.rb +134 -64
  137. data/spec/unit/provider/ifconfig/debian_spec.rb +19 -9
  138. data/spec/unit/provider/ifconfig/redhat_spec.rb +16 -14
  139. data/spec/unit/provider/ifconfig_spec.rb +3 -3
  140. data/spec/unit/provider/link_spec.rb +5 -5
  141. data/spec/unit/provider/mount/mount_spec.rb +10 -1
  142. data/spec/unit/provider/mount/solaris_spec.rb +185 -11
  143. data/spec/unit/provider/package/aix_spec.rb +5 -17
  144. data/spec/unit/provider/package/ips_spec.rb +8 -21
  145. data/spec/unit/provider/package/macports_spec.rb +12 -12
  146. data/spec/unit/provider/package/pacman_spec.rb +4 -12
  147. data/spec/unit/provider/package/portage_spec.rb +5 -15
  148. data/spec/unit/provider/package/rpm_spec.rb +7 -22
  149. data/spec/unit/provider/package/solaris_spec.rb +5 -16
  150. data/spec/unit/provider/service/arch_service_spec.rb +8 -14
  151. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  152. data/spec/unit/provider/service/freebsd_service_spec.rb +457 -225
  153. data/spec/unit/provider/service/gentoo_service_spec.rb +2 -2
  154. data/spec/unit/provider/service/init_service_spec.rb +10 -10
  155. data/spec/unit/provider/service/insserv_service_spec.rb +3 -4
  156. data/spec/unit/provider/service/invokercd_service_spec.rb +8 -9
  157. data/spec/unit/provider/service/macosx_spec.rb +5 -5
  158. data/spec/unit/provider/service/simple_service_spec.rb +4 -6
  159. data/spec/unit/provider/service/solaris_smf_service_spec.rb +1 -3
  160. data/spec/unit/provider/service/systemd_service_spec.rb +20 -20
  161. data/spec/unit/provider/service/upstart_service_spec.rb +15 -17
  162. data/spec/unit/provider/subversion_spec.rb +5 -6
  163. data/spec/unit/provider/user/dscl_spec.rb +2 -1
  164. data/spec/unit/provider/user/windows_spec.rb +7 -0
  165. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
  166. data/spec/unit/resource/mount_spec.rb +9 -0
  167. data/spec/unit/resource_spec.rb +0 -4
  168. data/spec/unit/rest_spec.rb +1 -1
  169. data/spec/unit/run_context_spec.rb +15 -0
  170. data/spec/unit/search/query_spec.rb +196 -40
  171. data/spec/unit/util/path_helper_spec.rb +111 -28
  172. data/spec/unit/workstation_config_loader_spec.rb +283 -0
  173. metadata +36 -20
  174. data/lib/chef/knife/bootstrap/centos5-gems.erb +0 -62
  175. data/lib/chef/knife/bootstrap/fedora13-gems.erb +0 -44
  176. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +0 -53
  177. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +0 -48
  178. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +0 -46
  179. data/spec/support/shared/integration/chef_zero_support.rb +0 -130
  180. data/spec/unit/knife/config_file_selection_spec.rb +0 -135
@@ -112,14 +112,10 @@ class Chef
112
112
  def install_package(name, version)
113
113
  Chef::Log.debug("#{@new_resource} package install options: #{@new_resource.options}")
114
114
  if @new_resource.options.nil?
115
- run_command_with_systems_locale(
116
- :command => "installp -aYF -d #{@new_resource.source} #{@new_resource.package_name}"
117
- )
115
+ shell_out!( "installp -aYF -d #{@new_resource.source} #{@new_resource.package_name}" )
118
116
  Chef::Log.debug("#{@new_resource} installed version #{@new_resource.version} from: #{@new_resource.source}")
119
117
  else
120
- run_command_with_systems_locale(
121
- :command => "installp -aYF #{expand_options(@new_resource.options)} -d #{@new_resource.source} #{@new_resource.package_name}"
122
- )
118
+ shell_out!( "installp -aYF #{expand_options(@new_resource.options)} -d #{@new_resource.source} #{@new_resource.package_name}" )
123
119
  Chef::Log.debug("#{@new_resource} installed version #{@new_resource.version} from: #{@new_resource.source}")
124
120
  end
125
121
  end
@@ -128,14 +124,10 @@ class Chef
128
124
 
129
125
  def remove_package(name, version)
130
126
  if @new_resource.options.nil?
131
- run_command_with_systems_locale(
132
- :command => "installp -u #{name}"
133
- )
127
+ shell_out!( "installp -u #{name}" )
134
128
  Chef::Log.debug("#{@new_resource} removed version #{@new_resource.version}")
135
129
  else
136
- run_command_with_systems_locale(
137
- :command => "installp -u #{expand_options(@new_resource.options)} #{name}"
138
- )
130
+ shell_out!( "installp -u #{expand_options(@new_resource.options)} #{name}" )
139
131
  Chef::Log.debug("#{@new_resource} removed version #{@new_resource.version}")
140
132
  end
141
133
  end
@@ -65,15 +65,13 @@ class Chef
65
65
  def install_package(name, version)
66
66
  package_name = "#{name}@#{version}"
67
67
  normal_command = "pkg#{expand_options(@new_resource.options)} install -q #{package_name}"
68
- if @new_resource.respond_to?(:accept_license) and @new_resource.accept_license
69
- command = normal_command.gsub('-q', '-q --accept')
70
- else
71
- command = normal_command
72
- end
73
- begin
74
- run_command_with_systems_locale(:command => command)
75
- rescue
76
- end
68
+ command =
69
+ if @new_resource.respond_to?(:accept_license) and @new_resource.accept_license
70
+ normal_command.gsub('-q', '-q --accept')
71
+ else
72
+ normal_command
73
+ end
74
+ shell_out(command)
77
75
  end
78
76
 
79
77
  def upgrade_package(name, version)
@@ -82,9 +80,7 @@ class Chef
82
80
 
83
81
  def remove_package(name, version)
84
82
  package_name = "#{name}@#{version}"
85
- run_command_with_systems_locale(
86
- :command => "pkg#{expand_options(@new_resource.options)} uninstall -q #{package_name}"
87
- )
83
+ shell_out!( "pkg#{expand_options(@new_resource.options)} uninstall -q #{package_name}" )
88
84
  end
89
85
  end
90
86
  end
@@ -45,27 +45,21 @@ class Chef
45
45
  unless @current_resource.version == version
46
46
  command = "port#{expand_options(@new_resource.options)} install #{name}"
47
47
  command << " @#{version}" if version and !version.empty?
48
- run_command_with_systems_locale(
49
- :command => command
50
- )
48
+ shell_out!(command)
51
49
  end
52
50
  end
53
51
 
54
52
  def purge_package(name, version)
55
53
  command = "port#{expand_options(@new_resource.options)} uninstall #{name}"
56
54
  command << " @#{version}" if version and !version.empty?
57
- run_command_with_systems_locale(
58
- :command => command
59
- )
55
+ shell_out!(command)
60
56
  end
61
57
 
62
58
  def remove_package(name, version)
63
59
  command = "port#{expand_options(@new_resource.options)} deactivate #{name}"
64
60
  command << " @#{version}" if version and !version.empty?
65
61
 
66
- run_command_with_systems_locale(
67
- :command => command
68
- )
62
+ shell_out!(command)
69
63
  end
70
64
 
71
65
  def upgrade_package(name, version)
@@ -78,9 +72,7 @@ class Chef
78
72
  # that hasn't been installed.
79
73
  install_package(name, version)
80
74
  elsif current_version != version
81
- run_command_with_systems_locale(
82
- :command => "port#{expand_options(@new_resource.options)} upgrade #{name} @#{version}"
83
- )
75
+ shell_out!( "port#{expand_options(@new_resource.options)} upgrade #{name} @#{version}" )
84
76
  end
85
77
  end
86
78
 
@@ -86,9 +86,7 @@ class Chef
86
86
  end
87
87
 
88
88
  def install_package(name, version)
89
- run_command_with_systems_locale(
90
- :command => "pacman --sync --noconfirm --noprogressbar#{expand_options(@new_resource.options)} #{name}"
91
- )
89
+ shell_out!( "pacman --sync --noconfirm --noprogressbar#{expand_options(@new_resource.options)} #{name}" )
92
90
  end
93
91
 
94
92
  def upgrade_package(name, version)
@@ -96,9 +94,7 @@ class Chef
96
94
  end
97
95
 
98
96
  def remove_package(name, version)
99
- run_command_with_systems_locale(
100
- :command => "pacman --remove --noconfirm --noprogressbar#{expand_options(@new_resource.options)} #{name}"
101
- )
97
+ shell_out!( "pacman --remove --noconfirm --noprogressbar#{expand_options(@new_resource.options)} #{name}" )
102
98
  end
103
99
 
104
100
  def purge_package(name, version)
@@ -110,9 +110,7 @@ class Chef
110
110
  pkg = "~#{name}-#{$1}"
111
111
  end
112
112
 
113
- run_command_with_systems_locale(
114
- :command => "emerge -g --color n --nospinner --quiet#{expand_options(@new_resource.options)} #{pkg}"
115
- )
113
+ shell_out!( "emerge -g --color n --nospinner --quiet#{expand_options(@new_resource.options)} #{pkg}" )
116
114
  end
117
115
 
118
116
  def upgrade_package(name, version)
@@ -126,9 +124,7 @@ class Chef
126
124
  pkg = "#{@new_resource.package_name}"
127
125
  end
128
126
 
129
- run_command_with_systems_locale(
130
- :command => "emerge --unmerge --color n --nospinner --quiet#{expand_options(@new_resource.options)} #{pkg}"
131
- )
127
+ shell_out!( "emerge --unmerge --color n --nospinner --quiet#{expand_options(@new_resource.options)} #{pkg}" )
132
128
  end
133
129
 
134
130
  def purge_package(name, version)
@@ -90,13 +90,9 @@ class Chef
90
90
 
91
91
  def install_package(name, version)
92
92
  unless @current_resource.version
93
- run_command_with_systems_locale(
94
- :command => "rpm #{@new_resource.options} -i #{@new_resource.source}"
95
- )
93
+ shell_out!( "rpm #{@new_resource.options} -i #{@new_resource.source}" )
96
94
  else
97
- run_command_with_systems_locale(
98
- :command => "rpm #{@new_resource.options} -U #{@new_resource.source}"
99
- )
95
+ shell_out!( "rpm #{@new_resource.options} -U #{@new_resource.source}" )
100
96
  end
101
97
  end
102
98
 
@@ -104,13 +100,9 @@ class Chef
104
100
 
105
101
  def remove_package(name, version)
106
102
  if version
107
- run_command_with_systems_locale(
108
- :command => "rpm #{@new_resource.options} -e #{name}-#{version}"
109
- )
103
+ shell_out!( "rpm #{@new_resource.options} -e #{name}-#{version}" )
110
104
  else
111
- run_command_with_systems_locale(
112
- :command => "rpm #{@new_resource.options} -e #{name}"
113
- )
105
+ shell_out!( "rpm #{@new_resource.options} -e #{name}" )
114
106
  end
115
107
  end
116
108
 
@@ -112,9 +112,7 @@ class Chef
112
112
  else
113
113
  command = "pkgadd -n -d #{@new_resource.source} all"
114
114
  end
115
- run_command_with_systems_locale(
116
- :command => command
117
- )
115
+ shell_out!(command)
118
116
  Chef::Log.debug("#{@new_resource} installed version #{@new_resource.version} from: #{@new_resource.source}")
119
117
  else
120
118
  if ::File.directory?(@new_resource.source) # CHEF-4469
@@ -122,23 +120,17 @@ class Chef
122
120
  else
123
121
  command = "pkgadd -n#{expand_options(@new_resource.options)} -d #{@new_resource.source} all"
124
122
  end
125
- run_command_with_systems_locale(
126
- :command => command
127
- )
123
+ shell_out!(command)
128
124
  Chef::Log.debug("#{@new_resource} installed version #{@new_resource.version} from: #{@new_resource.source}")
129
125
  end
130
126
  end
131
127
 
132
128
  def remove_package(name, version)
133
129
  if @new_resource.options.nil?
134
- run_command_with_systems_locale(
135
- :command => "pkgrm -n #{name}"
136
- )
130
+ shell_out!( "pkgrm -n #{name}" )
137
131
  Chef::Log.debug("#{@new_resource} removed version #{@new_resource.version}")
138
132
  else
139
- run_command_with_systems_locale(
140
- :command => "pkgrm -n#{expand_options(@new_resource.options)} #{name}"
141
- )
133
+ shell_out!( "pkgrm -n#{expand_options(@new_resource.options)} #{name}" )
142
134
  Chef::Log.debug("#{@new_resource} removed version #{@new_resource.version}")
143
135
  end
144
136
  end
@@ -0,0 +1,69 @@
1
+ #
2
+ # Author:: Chris Doherty <cdoherty@getchef.com>)
3
+ # Copyright:: Copyright (c) 2014 Chef, 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/log'
20
+ require 'chef/provider'
21
+
22
+ class Chef
23
+ class Provider
24
+ class Reboot < Chef::Provider
25
+
26
+ def whyrun_supported?
27
+ true
28
+ end
29
+
30
+ def load_current_resource
31
+ @current_resource ||= Chef::Resource::Reboot.new(@new_resource.name)
32
+ @current_resource.reason(@new_resource.reason)
33
+ @current_resource.delay_mins(@new_resource.delay_mins)
34
+ @current_resource
35
+ end
36
+
37
+ def request_reboot
38
+ node.run_context.request_reboot(
39
+ :delay_mins => @new_resource.delay_mins,
40
+ :reason => @new_resource.reason,
41
+ :timestamp => Time.now,
42
+ :requested_by => @new_resource.name
43
+ )
44
+ end
45
+
46
+ def action_request_reboot
47
+ converge_by("request a system reboot to occur if the run succeeds") do
48
+ Chef::Log.warn "Reboot requested:'#{@new_resource.name}'"
49
+ request_reboot
50
+ end
51
+ end
52
+
53
+ def action_reboot_now
54
+ converge_by("rebooting the system immediately") do
55
+ Chef::Log.warn "Rebooting system immediately, requested by '#{@new_resource.name}'"
56
+ request_reboot
57
+ throw :end_client_run_early
58
+ end
59
+ end
60
+
61
+ def action_cancel
62
+ converge_by("cancel any existing end-of-run reboot request") do
63
+ Chef::Log.warn "Reboot canceled: '#{@new_resource.name}'"
64
+ node.run_context.cancel_reboot
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -130,15 +130,15 @@ class Chef
130
130
 
131
131
  def enable_service
132
132
  if @new_resource.priority.is_a? Integer
133
- run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
134
- run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} defaults #{@new_resource.priority} #{100 - @new_resource.priority}")
133
+ shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
134
+ shell_out!("/usr/sbin/update-rc.d #{@new_resource.service_name} defaults #{@new_resource.priority} #{100 - @new_resource.priority}")
135
135
  elsif @new_resource.priority.is_a? Hash
136
136
  # we call the same command regardless of we're enabling or disabling
137
137
  # users passing a Hash are responsible for setting their own start priorities
138
138
  set_priority
139
139
  else # No priority, go with update-rc.d defaults
140
- run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
141
- run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} defaults")
140
+ shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
141
+ shell_out!("/usr/sbin/update-rc.d #{@new_resource.service_name} defaults")
142
142
  end
143
143
 
144
144
  end
@@ -146,16 +146,16 @@ class Chef
146
146
  def disable_service
147
147
  if @new_resource.priority.is_a? Integer
148
148
  # Stop processes in reverse order of start using '100 - start_priority'
149
- run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
150
- run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} stop #{100 - @new_resource.priority} 2 3 4 5 .")
149
+ shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
150
+ shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} stop #{100 - @new_resource.priority} 2 3 4 5 .")
151
151
  elsif @new_resource.priority.is_a? Hash
152
152
  # we call the same command regardless of we're enabling or disabling
153
153
  # users passing a Hash are responsible for setting their own stop priorities
154
154
  set_priority
155
155
  else
156
156
  # no priority, using '100 - 20 (update-rc.d default)' to stop in reverse order of start
157
- run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
158
- run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} stop 80 2 3 4 5 .")
157
+ shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
158
+ shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} stop 80 2 3 4 5 .")
159
159
  end
160
160
  end
161
161
 
@@ -166,8 +166,8 @@ class Chef
166
166
  priority = o[1]
167
167
  args += "#{action} #{priority} #{level} . "
168
168
  end
169
- run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
170
- run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} #{args}")
169
+ shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
170
+ shell_out!("/usr/sbin/update-rc.d #{@new_resource.service_name} #{args}")
171
171
  end
172
172
  end
173
173
  end
@@ -25,89 +25,76 @@ class Chef
25
25
  class Service
26
26
  class Freebsd < Chef::Provider::Service::Init
27
27
 
28
- def load_current_resource
29
- @current_resource = Chef::Resource::Service.new(@new_resource.name)
30
- @current_resource.service_name(@new_resource.service_name)
31
- @rcd_script_found = true
28
+ attr_reader :enabled_state_found
29
+
30
+ def initialize(new_resource, run_context)
31
+ super
32
32
  @enabled_state_found = false
33
- # Determine if we're talking about /etc/rc.d or /usr/local/etc/rc.d
34
- if ::File.exists?("/etc/rc.d/#{current_resource.service_name}")
35
- @init_command = "/etc/rc.d/#{current_resource.service_name}"
36
- elsif ::File.exists?("/usr/local/etc/rc.d/#{current_resource.service_name}")
37
- @init_command = "/usr/local/etc/rc.d/#{current_resource.service_name}"
38
- else
39
- @rcd_script_found = false
40
- return
41
- end
42
- Chef::Log.debug("#{@current_resource} found at #{@init_command}")
43
- determine_current_status!
44
- # Default to disabled if the service doesn't currently exist
45
- # at all
46
- var_name = service_enable_variable_name
47
- if ::File.exists?("/etc/rc.conf") && var_name
48
- read_rc_conf.each do |line|
49
- case line
50
- when /#{Regexp.escape(var_name)}="(\w+)"/
51
- @enabled_state_found = true
52
- if $1 =~ /[Yy][Ee][Ss]/
53
- @current_resource.enabled true
54
- elsif $1 =~ /[Nn][Oo][Nn]?[Oo]?[Nn]?[Ee]?/
55
- @current_resource.enabled false
56
- end
57
- end
58
- end
59
- end
60
- unless @current_resource.enabled
61
- Chef::Log.debug("#{@new_resource.name} enable/disable state unknown")
62
- @current_resource.enabled false
33
+ @init_command = nil
34
+ if ::File.exist?("/etc/rc.d/#{new_resource.service_name}")
35
+ @init_command = "/etc/rc.d/#{new_resource.service_name}"
36
+ elsif ::File.exist?("/usr/local/etc/rc.d/#{new_resource.service_name}")
37
+ @init_command = "/usr/local/etc/rc.d/#{new_resource.service_name}"
63
38
  end
39
+ end
40
+
41
+ def load_current_resource
42
+ @current_resource = Chef::Resource::Service.new(new_resource.name)
43
+ current_resource.service_name(new_resource.service_name)
44
+
45
+ return current_resource unless init_command
64
46
 
65
- @current_resource
47
+ Chef::Log.debug("#{current_resource} found at #{init_command}")
48
+
49
+ determine_current_status! # see Chef::Provider::Service::Simple
50
+
51
+ determine_enabled_status!
52
+ current_resource
66
53
  end
67
54
 
68
55
  def define_resource_requirements
69
56
  shared_resource_requirements
57
+
70
58
  requirements.assert(:start, :enable, :reload, :restart) do |a|
71
- a.assertion { @rcd_script_found }
72
- a.failure_message Chef::Exceptions::Service, "#{@new_resource}: unable to locate the rc.d script"
59
+ a.assertion { init_command }
60
+ a.failure_message Chef::Exceptions::Service, "#{new_resource}: unable to locate the rc.d script"
73
61
  end
74
62
 
75
63
  requirements.assert(:all_actions) do |a|
76
- a.assertion { @enabled_state_found }
64
+ a.assertion { enabled_state_found }
77
65
  # for consistentcy with original behavior, this will not fail in non-whyrun mode;
78
66
  # rather it will silently set enabled state=>false
79
67
  a.whyrun "Unable to determine enabled/disabled state, assuming this will be correct for an actual run. Assuming disabled."
80
68
  end
81
69
 
82
70
  requirements.assert(:start, :enable, :reload, :restart) do |a|
83
- a.assertion { @rcd_script_found && service_enable_variable_name != nil }
84
- a.failure_message Chef::Exceptions::Service, "Could not find the service name in #{@init_command} and rcvar"
71
+ a.assertion { init_command && service_enable_variable_name != nil }
72
+ a.failure_message Chef::Exceptions::Service, "Could not find the service name in #{init_command} and rcvar"
85
73
  # No recovery in whyrun mode - the init file is present but not correct.
86
74
  end
87
75
  end
88
76
 
89
77
  def start_service
90
- if @new_resource.start_command
78
+ if new_resource.start_command
91
79
  super
92
80
  else
93
- shell_out!("#{@init_command} faststart")
81
+ shell_out_with_systems_locale!("#{init_command} faststart")
94
82
  end
95
83
  end
96
84
 
97
85
  def stop_service
98
- if @new_resource.stop_command
86
+ if new_resource.stop_command
99
87
  super
100
88
  else
101
- shell_out!("#{@init_command} faststop")
89
+ shell_out_with_systems_locale!("#{init_command} faststop")
102
90
  end
103
91
  end
104
92
 
105
93
  def restart_service
106
- if @new_resource.restart_command
107
-
94
+ if new_resource.restart_command
108
95
  super
109
- elsif @new_resource.supports[:restart]
110
- shell_out!("#{@init_command} fastrestart")
96
+ elsif new_resource.supports[:restart]
97
+ shell_out_with_systems_locale!("#{init_command} fastrestart")
111
98
  else
112
99
  stop_service
113
100
  sleep 1
@@ -115,6 +102,16 @@ class Chef
115
102
  end
116
103
  end
117
104
 
105
+ def enable_service
106
+ set_service_enable("YES") unless current_resource.enabled
107
+ end
108
+
109
+ def disable_service
110
+ set_service_enable("NO") if current_resource.enabled
111
+ end
112
+
113
+ private
114
+
118
115
  def read_rc_conf
119
116
  ::File.open("/etc/rc.conf", 'r') { |file| file.readlines }
120
117
  end
@@ -127,46 +124,65 @@ class Chef
127
124
 
128
125
  # The variable name used in /etc/rc.conf for enabling this service
129
126
  def service_enable_variable_name
130
- # Look for name="foo" in the shell script @init_command. Use this for determining the variable name in /etc/rc.conf
131
- # corresponding to this service
132
- # For example: to enable the service mysql-server with the init command /usr/local/etc/rc.d/mysql-server, you need
133
- # to set mysql_enable="YES" in /etc/rc.conf$
134
- if @rcd_script_found
135
- ::File.open(@init_command) do |rcscript|
136
- rcscript.each_line do |line|
137
- if line =~ /^name="?(\w+)"?/
138
- return $1 + "_enable"
127
+ @service_enable_variable_name ||=
128
+ begin
129
+ # Look for name="foo" in the shell script @init_command. Use this for determining the variable name in /etc/rc.conf
130
+ # corresponding to this service
131
+ # For example: to enable the service mysql-server with the init command /usr/local/etc/rc.d/mysql-server, you need
132
+ # to set mysql_enable="YES" in /etc/rc.conf$
133
+ if init_command
134
+ ::File.open(init_command) do |rcscript|
135
+ rcscript.each_line do |line|
136
+ if line =~ /^name="?(\w+)"?/
137
+ return $1 + "_enable"
138
+ end
139
+ end
140
+ end
141
+ # some scripts support multiple instances through symlinks such as openvpn.
142
+ # We should get the service name from rcvar.
143
+ Chef::Log.debug("name=\"service\" not found at #{init_command}. falling back to rcvar")
144
+ sn = shell_out!("#{init_command} rcvar").stdout[/(\w+_enable)=/, 1]
145
+ else
146
+ # for why-run mode when the rcd_script is not there yet
147
+ new_resource.service_name
148
+ end
149
+ end
150
+ end
151
+
152
+ def determine_enabled_status!
153
+ var_name = service_enable_variable_name
154
+ if ::File.exist?("/etc/rc.conf") && var_name
155
+ read_rc_conf.each do |line|
156
+ case line
157
+ when /^#{Regexp.escape(var_name)}="(\w+)"/
158
+ enabled_state_found!
159
+ if $1 =~ /^yes$/i
160
+ current_resource.enabled true
161
+ elsif $1 =~ /^(no|none)$/i
162
+ current_resource.enabled false
139
163
  end
140
164
  end
141
165
  end
142
- # some scripts support multiple instances through symlinks such as openvpn.
143
- # We should get the service name from rcvar.
144
- Chef::Log.debug("name=\"service\" not found at #{@init_command}. falling back to rcvar")
145
- sn = shell_out!("#{@init_command} rcvar").stdout[/(\w+_enable)=/, 1]
146
- return sn
147
166
  end
148
- # Fallback allows us to keep running in whyrun mode when
149
- # the script does not exist.
150
- @new_resource.service_name
167
+
168
+ if current_resource.enabled.nil?
169
+ Chef::Log.debug("#{new_resource.name} enable/disable state unknown")
170
+ current_resource.enabled false
171
+ end
151
172
  end
152
173
 
153
174
  def set_service_enable(value)
154
175
  lines = read_rc_conf
155
176
  # Remove line that set the old value
156
- lines.delete_if { |line| line =~ /#{Regexp.escape(service_enable_variable_name)}/ }
177
+ lines.delete_if { |line| line =~ /^#{Regexp.escape(service_enable_variable_name)}=/ }
157
178
  # And append the line that sets the new value at the end
158
179
  lines << "#{service_enable_variable_name}=\"#{value}\""
159
180
  write_rc_conf(lines)
160
181
  end
161
182
 
162
- def enable_service()
163
- set_service_enable("YES") unless @current_resource.enabled
164
- end
165
-
166
- def disable_service()
167
- set_service_enable("NO") if @current_resource.enabled
183
+ def enabled_state_found!
184
+ @enabled_state_found = true
168
185
  end
169
-
170
186
  end
171
187
  end
172
188
  end