chef 10.30.4-x86-mingw32 → 10.32.0.rc.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/distro/common/html/chef-client.8.html +4 -4
  3. data/distro/common/html/chef-expander.8.html +4 -4
  4. data/distro/common/html/chef-expanderctl.8.html +4 -4
  5. data/distro/common/html/chef-server-webui.8.html +4 -4
  6. data/distro/common/html/chef-server.8.html +4 -4
  7. data/distro/common/html/chef-solo.8.html +4 -4
  8. data/distro/common/html/chef-solr.8.html +5 -5
  9. data/distro/common/html/knife-bootstrap.1.html +4 -4
  10. data/distro/common/html/knife-client.1.html +4 -4
  11. data/distro/common/html/knife-configure.1.html +4 -4
  12. data/distro/common/html/knife-cookbook-site.1.html +4 -4
  13. data/distro/common/html/knife-cookbook.1.html +4 -4
  14. data/distro/common/html/knife-data-bag.1.html +4 -4
  15. data/distro/common/html/knife-environment.1.html +4 -4
  16. data/distro/common/html/knife-exec.1.html +4 -4
  17. data/distro/common/html/knife-index.1.html +4 -4
  18. data/distro/common/html/knife-node.1.html +4 -4
  19. data/distro/common/html/knife-role.1.html +4 -4
  20. data/distro/common/html/knife-search.1.html +4 -4
  21. data/distro/common/html/knife-ssh.1.html +4 -4
  22. data/distro/common/html/knife-status.1.html +4 -4
  23. data/distro/common/html/knife-tag.1.html +4 -4
  24. data/distro/common/html/knife.1.html +4 -4
  25. data/distro/common/html/shef.1.html +4 -4
  26. data/distro/common/man/man1/knife-bootstrap.1 +0 -201
  27. data/distro/common/man/man1/knife-client.1 +0 -99
  28. data/distro/common/man/man1/knife-configure.1 +0 -88
  29. data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
  30. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  31. data/distro/common/man/man1/knife-data-bag.1 +1 -1
  32. data/distro/common/man/man1/knife-environment.1 +1 -1
  33. data/distro/common/man/man1/knife-exec.1 +1 -1
  34. data/distro/common/man/man1/knife-index.1 +1 -1
  35. data/distro/common/man/man1/knife-node.1 +1 -1
  36. data/distro/common/man/man1/knife-role.1 +1 -1
  37. data/distro/common/man/man1/knife-search.1 +1 -1
  38. data/distro/common/man/man1/knife-ssh.1 +1 -1
  39. data/distro/common/man/man1/knife-status.1 +1 -1
  40. data/distro/common/man/man1/knife-tag.1 +1 -1
  41. data/distro/common/man/man1/knife.1 +1 -1
  42. data/distro/common/man/man1/shef.1 +1 -1
  43. data/distro/common/man/man8/chef-client.8 +1 -1
  44. data/distro/common/man/man8/chef-expander.8 +1 -1
  45. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  46. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  47. data/distro/common/man/man8/chef-server.8 +1 -1
  48. data/distro/common/man/man8/chef-solo.8 +1 -1
  49. data/distro/common/man/man8/chef-solr.8 +1 -1
  50. data/lib/chef/api_client.rb +22 -0
  51. data/lib/chef/checksum_cache.rb +1 -1
  52. data/lib/chef/provider/service/macosx.rb +69 -15
  53. data/lib/chef/version.rb +1 -1
  54. data/spec/unit/api_client_spec.rb +58 -0
  55. data/spec/unit/provider/service/macosx_spec.rb +29 -11
  56. metadata +117 -193
@@ -1,88 +0,0 @@
1
- .\" generated with Ronn/v0.7.3
2
- .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
- .
4
- .TH "KNIFE\-CONFIGURE" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
5
- .
6
- .SH "NAME"
7
- \fBknife\-configure\fR \- Generate configuration files for knife or Chef Client
8
- .
9
- .SH "SYNOPSIS"
10
- \fBknife\fR \fBconfigure\fR [client] \fI(options)\fR
11
- .
12
- .SH "DESCRIPTION"
13
- Generates a knife\.rb configuration file interactively\. When given the \-\-initial option, also creates a new administrative user\.
14
- .
15
- .SH "CONFIGURE SUBCOMMANDS"
16
- \fBknife configure\fR \fI(options)\fR
17
- .
18
- .TP
19
- \fB\-i\fR, \fB\-\-initial\fR
20
- Create an initial API Client
21
- .
22
- .TP
23
- \fB\-r\fR, \fB\-\-repository REPO\fR
24
- The path to your chef\-repo
25
- .
26
- .P
27
- Create a configuration file for knife\. This will prompt for values to enter into the file\. Default values are listed in square brackets if no other entry is typed\. See \fBknife\fR(1) for a description of configuration options\.
28
- .
29
- .P
30
- \fBknife configure client\fR \fIdirectory\fR
31
- .
32
- .P
33
- Read the \fIknife\.rb\fR config file and generate a config file suitable for use in \fI/etc/chef/client\.rb\fR and copy the validation certificate into the specified \fIdirectory\fR\.
34
- .
35
- .SH "EXAMPLES"
36
- .
37
- .IP "\(bu" 4
38
- On a freshly installed Chef Server, use \fIknife configure \-i\fR to create an administrator and knife configuration file\. Leave the field blank to accept the default value\. On most systems, the default values are acceptable\.
39
- .
40
- .IP
41
- user@host$ knife configure \-i
42
- .
43
- .br
44
- Please enter the chef server URL: [http://localhost:4000]
45
- .
46
- .br
47
- Please enter a clientname for the new client: [username]
48
- .
49
- .br
50
- Please enter the existing admin clientname: [chef\-webui]
51
- .
52
- .br
53
- Please enter the location of the existing admin client\'s private key: [/etc/chef/webui\.pem]
54
- .
55
- .br
56
- Please enter the validation clientname: [chef\-validator]
57
- .
58
- .br
59
- Please enter the location of the validation key: [/etc/chef/validation\.pem]
60
- .
61
- .br
62
- Please enter the path to a chef repository (or leave blank):
63
- .
64
- .br
65
- Creating initial API user\.\.\.
66
- .
67
- .br
68
- Created (or updated) client[username]
69
- .
70
- .br
71
- Configuration file written to /home/username/\.chef/knife\.rb
72
- .
73
- .IP
74
- This creates a new administrator client named \fIusername\fR, writes a configuration file to \fI/home/username/\.chef/knife\.rb\fR, and the private key to \fI/home/username/\.chef/username\.pem\fR\. The configuration file and private key may be copied to another system to facilitate administration of the Chef Server from a remote system\. Depending on the value given for the Chef Server URL, you may need to modify that setting after copying to a remote host\.
75
- .
76
- .IP "" 0
77
- .
78
- .SH "SEE ALSO"
79
- \fBknife\fR(1) \fBknife\-client\fR(1)
80
- .
81
- .SH "AUTHOR"
82
- Chef was written by Adam Jacob \fIadam@opscode\.com\fR with many contributions from the community\.
83
- .
84
- .SH "DOCUMENTATION"
85
- This manual page was written by Joshua Timberman \fIjoshua@opscode\.com\fR\. Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2\.0 License\.
86
- .
87
- .SH "CHEF"
88
- Knife is distributed with Chef\. \fIhttp://wiki\.opscode\.com/display/chef/Home\fR
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-COOKBOOK\-SITE" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-COOKBOOK\-SITE" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-cookbook\-site\fR \- Install and update open source cookbooks
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-COOKBOOK" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-COOKBOOK" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-cookbook\fR \- upload and manage chef cookbooks
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-DATA\-BAG" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-DATA\-BAG" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-data\-bag\fR \- Store arbitrary data on a Chef Server
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-ENVIRONMENT" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-ENVIRONMENT" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-environment\fR \- Define cookbook policies for the environments in your infrastructure
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-EXEC" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-EXEC" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-exec\fR \- Run user scripts using the Chef API DSL
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-INDEX" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-INDEX" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-index\fR \- Rebuild the search index on a Chef Server
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-NODE" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-NODE" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-node\fR \- Manage the hosts in your infrastructure
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-ROLE" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-ROLE" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-role\fR \- Group common configuration settings
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-SEARCH" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-SEARCH" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-search\fR \- Find objects on a Chef Server by query
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-SSH" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-SSH" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-ssh\fR \- Run a command or interactive session on multiple remote hosts
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-STATUS" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-STATUS" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-status\fR \- Display status information for the nodes in your infrastructure
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE\-TAG" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE\-TAG" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\-tag\fR \- Apply tags to nodes on a Chef Server
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "KNIFE" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "KNIFE" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBknife\fR \- Chef Server API client utility
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "SHEF" "1" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "SHEF" "1" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBshef\fR \- Interactive Chef Console
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "CHEF\-CLIENT" "8" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "CHEF\-CLIENT" "8" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBchef\-client\fR \- Runs a client node connecting to a chef\-server\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "CHEF\-EXPANDER" "8" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "CHEF\-EXPANDER" "8" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBchef\-expander\fR \- fetches messages from RabbitMQ, processes, and loads into chef\-solr
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "CHEF\-EXPANDERCTL" "8" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "CHEF\-EXPANDERCTL" "8" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBchef\-expanderctl\fR \- management program for chef\-expander
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "CHEF\-SERVER\-WEBUI" "8" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "CHEF\-SERVER\-WEBUI" "8" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBchef\-server\-webui\fR \- Start the Chef Server merb application slice providing Web User Interface (Management Console)\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "CHEF\-SERVER" "8" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "CHEF\-SERVER" "8" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBchef\-server\fR \- Start the Chef Server merb application slice\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "CHEF\-SOLO" "8" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "CHEF\-SOLO" "8" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBchef\-solo\fR \- Runs chef in solo mode against a specified cookbook location\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "CHEF\-SOLR" "8" "February 2014" "Chef 10.30.4" "Chef Manual"
4
+ .TH "CHEF\-SOLR" "8" "March 2014" "Chef 10.32.0.rc.0" "Chef Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBchef\-solr\fR \- Runs as Chef\'s search server
@@ -239,6 +239,9 @@ class Chef
239
239
 
240
240
  # Save this client via the REST API, returns a hash including the private key
241
241
  def save(new_key=false, validation=false)
242
+ # Implement CHEF-4373 with minimal churn to existing code:
243
+ return register_with_self_generated_key if new_key && validation && Chef::Config.local_key_generation
244
+
242
245
  if validation
243
246
  r = Chef::REST.new(Chef::Config[:chef_server_url], Chef::Config[:validation_client_name], Chef::Config[:validation_key])
244
247
  else
@@ -257,6 +260,25 @@ class Chef
257
260
  end
258
261
  end
259
262
 
263
+ def register_with_self_generated_key
264
+ r = Chef::REST.new(Chef::Config[:chef_server_url], Chef::Config[:validation_client_name], Chef::Config[:validation_key])
265
+ pkey = OpenSSL::PKey::RSA.generate(2048)
266
+ client_data = {:name => name, :admin => false , :public_key => pkey.public_key.to_pem}
267
+ # First, try and create a new registration
268
+ r = begin
269
+ r.post_rest("clients", client_data)
270
+ rescue Net::HTTPServerException => e
271
+ # If that fails, go ahead and try and update it
272
+ if e.response.code == "409"
273
+ r.put_rest("clients/#{name}", client_data)
274
+ else
275
+ raise e
276
+ end
277
+ end
278
+ private_key(pkey.to_pem)
279
+ self
280
+ end
281
+
260
282
  def reregister
261
283
  r = Chef::REST.new(Chef::Config[:chef_server_url])
262
284
  reregistered_self = r.put_rest("clients/#{name}", { :name => name, :admin => admin, :private_key => true })
@@ -149,7 +149,7 @@ class Chef
149
149
 
150
150
  def fetch(key)
151
151
  @moneta.fetch(key)
152
- rescue ArgumentError => e
152
+ rescue ArgumentError, TypeError => e
153
153
  Log.warn "Error loading cached checksum for key #{key.inspect}"
154
154
  Log.warn(e)
155
155
  repair_checksum_cache
@@ -17,6 +17,7 @@
17
17
  #
18
18
 
19
19
  require 'chef/provider/service'
20
+ require 'rexml/document'
20
21
 
21
22
  class Chef
22
23
  class Provider
@@ -35,6 +36,7 @@ class Chef
35
36
  @current_resource.service_name(@new_resource.service_name)
36
37
  @plist_size = 0
37
38
  @plist = find_service_plist
39
+ @service_label = find_service_label
38
40
  set_service_status
39
41
 
40
42
  @current_resource
@@ -42,14 +44,6 @@ class Chef
42
44
 
43
45
  def define_resource_requirements
44
46
  #super
45
- requirements.assert(:enable) do |a|
46
- a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
47
- end
48
-
49
- requirements.assert(:disable) do |a|
50
- a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
51
- end
52
-
53
47
  requirements.assert(:reload) do |a|
54
48
  a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload"
55
49
  end
@@ -59,16 +53,21 @@ class Chef
59
53
  a.failure_message Chef::Exceptions::Service, "Several plist files match service name. Please use full service name."
60
54
  end
61
55
 
56
+ requirements.assert(:all_actions) do |a|
57
+ a.assertion { !@service_label.to_s.empty? }
58
+ a.failure_message Chef::Exceptions::Service,
59
+ "Could not find service's label in plist file '#{@plist}'!"
60
+ end
61
+
62
62
  requirements.assert(:all_actions) do |a|
63
63
  a.assertion { @plist_size > 0 }
64
- # No failrue here in original code - so we also will not
64
+ # No failure here in original code - so we also will not
65
65
  # fail. Instead warn that the service is potentially missing
66
66
  a.whyrun "Assuming that the service would have been previously installed and is currently disabled." do
67
67
  @current_resource.enabled(false)
68
68
  @current_resource.running(false)
69
69
  end
70
70
  end
71
-
72
71
  end
73
72
 
74
73
  def start_service
@@ -105,19 +104,56 @@ class Chef
105
104
  end
106
105
  end
107
106
 
107
+ # On OS/X, enabling a service has the side-effect of starting it,
108
+ # and disabling a service has the side-effect of stopping it.
109
+ #
110
+ # This makes some sense on OS/X since launchctl is an "init"-style
111
+ # supervisor that will restart daemons that are crashing, etc.
112
+ def enable_service
113
+ if @current_resource.enabled
114
+ Chef::Log.debug("#{@new_resource} already enabled, not enabling")
115
+ else
116
+ shell_out!(
117
+ "launchctl load -w '#{@plist}'",
118
+ :user => @owner_uid, :group => @owner_gid
119
+ )
120
+ end
121
+ end
122
+
123
+ def disable_service
124
+ unless @current_resource.enabled
125
+ Chef::Log.debug("#{@new_resource} not enabled, not disabling")
126
+ else
127
+ shell_out!(
128
+ "launchctl unload -w '#{@plist}'",
129
+ :user => @owner_uid, :group => @owner_gid
130
+ )
131
+ end
132
+ end
108
133
 
109
134
  def set_service_status
110
- return if @plist == nil
135
+ return if @plist == nil or @service_label.to_s.empty?
111
136
 
112
- @current_resource.enabled(!@plist.nil?)
137
+ cmd = shell_out(
138
+ "launchctl list #{@service_label}",
139
+ :user => @owner_uid, :group => @owner_gid
140
+ )
141
+
142
+ if cmd.exitstatus == 0
143
+ @current_resource.enabled(true)
144
+ else
145
+ @current_resource.enabled(false)
146
+ end
113
147
 
114
148
  if @current_resource.enabled
115
149
  @owner_uid = ::File.stat(@plist).uid
116
150
  @owner_gid = ::File.stat(@plist).gid
117
151
 
118
- shell_out!("launchctl list", :user => @owner_uid, :group => @owner_gid).stdout.each_line do |line|
152
+ shell_out!(
153
+ "launchctl list", :user => @owner_uid, :group => @owner_gid
154
+ ).stdout.each_line do |line|
119
155
  case line
120
- when /(\d+|-)\s+(?:\d+|-)\s+(.*\.?)#{@current_resource.service_name}/
156
+ when /(\d+|-)\s+(?:\d+|-)\s+(.*\.?)#{@service_label}/
121
157
  pid = $1
122
158
  @current_resource.running(!pid.to_i.zero?)
123
159
  end
@@ -129,9 +165,27 @@ class Chef
129
165
 
130
166
  private
131
167
 
168
+ def find_service_label
169
+ # Most services have the same internal label as the name of the
170
+ # plist file. However, there is no rule saying that *has* to be
171
+ # the case, and some core services (notably, ssh) do not follow
172
+ # this rule.
173
+
174
+ # plist files can come in XML or Binary formats. this command
175
+ # will make sure we get XML every time.
176
+ plist_xml = shell_out!("plutil -convert xml1 -o - #{@plist}").stdout
177
+
178
+ plist_doc = REXML::Document.new(plist_xml)
179
+ plist_doc.elements[
180
+ "/plist/dict/key[text()='Label']/following::string[1]/text()"]
181
+ end
182
+
132
183
  def find_service_plist
133
184
  plists = PLIST_DIRS.inject([]) do |results, dir|
134
- entries = Dir.glob("#{::File.expand_path(dir)}/*#{@current_resource.service_name}*.plist")
185
+ edir = ::File.expand_path(dir)
186
+ entries = Dir.glob(
187
+ "#{edir}/*#{@current_resource.service_name}*.plist"
188
+ )
135
189
  entries.any? ? results << entries : results
136
190
  end
137
191
  plists.flatten!