diff options
author | Igor Afonov <afonov@gmail.com> | 2013-02-05 21:05:46 +0200 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-05-31 15:35:59 -0700 |
commit | fdc5c212c8d81c51c73552ab1d109196c685ae4c (patch) | |
tree | 11b45dd31df0d3fdbd11a8c86e268af815da9426 /lib/chef/provider/service/macosx.rb | |
parent | 8d6d5ab73f5ee588cafbfc0a41ff3521eb8b1664 (diff) | |
download | chef-fdc5c212c8d81c51c73552ab1d109196c685ae4c.tar.gz |
[CHEF-3237] Fix Mac OS X service provider. Do not fail when HOME is not set
* Do not add `~/Library/LaunchAgents` if HOME is not set
* It is safe to assume that if HOME is not set ~ will not expand - see rb_home_dir function in MRI ruby
Diffstat (limited to 'lib/chef/provider/service/macosx.rb')
-rw-r--r-- | lib/chef/provider/service/macosx.rb | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb index 72c02779c6..9dbde210f8 100644 --- a/lib/chef/provider/service/macosx.rb +++ b/lib/chef/provider/service/macosx.rb @@ -24,12 +24,19 @@ class Chef class Macosx < Chef::Provider::Service::Simple include Chef::Mixin::ShellOut - PLIST_DIRS = %w{~/Library/LaunchAgents - /Library/LaunchAgents + def self.gather_plist_dirs + locations = %w{/Library/LaunchAgents /Library/LaunchDaemons /System/Library/LaunchAgents /System/Library/LaunchDaemons } + locations.tap do |locations| + locations << '~/Library/LaunchAgents' if ENV['HOME'] + end + end + + PLIST_DIRS = Macosx.gather_plist_dirs + def load_current_resource @current_resource = Chef::Resource::Service.new(@new_resource.name) @current_resource.service_name(@new_resource.service_name) @@ -42,28 +49,28 @@ class Chef def define_resource_requirements #super - requirements.assert(:enable) do |a| + requirements.assert(:enable) do |a| a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable" end - requirements.assert(:disable) do |a| + requirements.assert(:disable) do |a| a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable" end - requirements.assert(:reload) do |a| + requirements.assert(:reload) do |a| a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload" end - requirements.assert(:all_actions) do |a| - a.assertion { @plist_size < 2 } + requirements.assert(:all_actions) do |a| + a.assertion { @plist_size < 2 } a.failure_message Chef::Exceptions::Service, "Several plist files match service name. Please use full service name." end - requirements.assert(:all_actions) do |a| - a.assertion { @plist_size > 0 } + requirements.assert(:all_actions) do |a| + a.assertion { @plist_size > 0 } # No failrue here in original code - so we also will not # fail. Instead warn that the service is potentially missing - a.whyrun "Assuming that the service would have been previously installed and is currently disabled." do + a.whyrun "Assuming that the service would have been previously installed and is currently disabled." do @current_resource.enabled(false) @current_resource.running(false) end |