diff options
author | Lamont Granquist <lamont@chef.io> | 2020-05-06 18:40:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-06 18:40:05 -0700 |
commit | 740396debdde52176a91c6a78d949f7f345ef69e (patch) | |
tree | b2bda892f4db96f8e8d326a7092c7473683c1d2e | |
parent | 021df024c4ea8529557c080ffe9ffb4133ee7ae8 (diff) | |
parent | 011eb4b1826d1f0cda4bddac526f938cc0cb6cef (diff) | |
download | chef-740396debdde52176a91c6a78d949f7f345ef69e.tar.gz |
Merge pull request #9812 from chef/lcg/fix-unified-mode-launchd
-rw-r--r-- | lib/chef/provider/launchd.rb | 42 | ||||
-rw-r--r-- | lib/chef/provider/service/macosx.rb | 6 | ||||
-rw-r--r-- | spec/unit/provider/launchd_spec.rb | 16 |
3 files changed, 30 insertions, 34 deletions
diff --git a/lib/chef/provider/launchd.rb b/lib/chef/provider/launchd.rb index fbb9307712..579a53fe03 100644 --- a/lib/chef/provider/launchd.rb +++ b/lib/chef/provider/launchd.rb @@ -36,7 +36,6 @@ class Chef label mode owner - path source session_type type @@ -44,7 +43,6 @@ class Chef def load_current_resource current_resource = Chef::Resource::Launchd.new(new_resource.name) - @path = path ? path : gen_path_from_type end def gen_path_from_type @@ -90,25 +88,16 @@ class Chef def manage_plist(action) if source - cookbook_file @path do - cookbook_name = cookbook if cookbook - name(@path) if @path - backup(backup) if backup - group(group) if group - mode(mode) if mode - owner(owner) if owner - source(source) if source + cookbook_file path do + cookbook_name = new_resource.cookbook if new_resource.cookbook + copy_properties_from(new_resource, :backup, :group, :mode, :owner, :source) action(action) only_if { manage_agent?(action) } end else - file @path do - name(@path) if @path - backup(backup) if backup - content(content) if content? - group(group) if group - mode(mode) if mode - owner(owner) if owner + file path do + copy_properties_from(new_resource, :backup, :group, :mode, :owner) + content(file_content) if file_content? action(action) only_if { manage_agent?(action) } end @@ -116,11 +105,11 @@ class Chef end def manage_service(action) + plist_path = path macosx_service label do - name(label) if label - service_name(label) if label - plist(@path) if @path - session_type(session_type) if session_type + service_name(new_resource.label) if new_resource.label + plist(plist_path) if plist_path + copy_properties_from(new_resource, :session_type) action(action) only_if { manage_agent?(action) } end @@ -155,11 +144,11 @@ class Chef end end - def content? - !!content + def file_content? + !!file_content end - def content + def file_content plist_hash = new_resource.plist_hash || gen_hash ::Plist::Emit.dump(plist_hash) unless plist_hash.nil? end @@ -215,6 +204,11 @@ class Chef memo[val] = new_resource.send(key) if new_resource.send(key) end end + + # @api private + def path + @path = new_resource.path ? new_resource.path : gen_path_from_type + end end end end diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb index 6e8663b7d4..ecd0e9e455 100644 --- a/lib/chef/provider/service/macosx.rb +++ b/lib/chef/provider/service/macosx.rb @@ -56,8 +56,10 @@ class Chef if @console_user @console_user = Etc.getpwuid(::File.stat("/dev/console").uid).name logger.trace("#{new_resource} console_user: '#{@console_user}'") - cmd = "su -l" - @base_user_cmd = cmd + "#{@console_user} -c" + + @base_user_cmd = "su -l #{@console_user} -c" + logger.trace("#{new_resource} base_user_cmd: '#{@base_user_cmd}'") + # Default LaunchAgent session should be Aqua @session_type = "Aqua" if @session_type.nil? end diff --git a/spec/unit/provider/launchd_spec.rb b/spec/unit/provider/launchd_spec.rb index 53b56b4960..69f0f315d0 100644 --- a/spec/unit/provider/launchd_spec.rb +++ b/spec/unit/provider/launchd_spec.rb @@ -131,8 +131,8 @@ describe Chef::Provider::Launchd do new_resource.program "/Library/scripts/call_mom.sh" new_resource.time_out 300 new_resource.start_calendar_interval "Hour" => 10, "Weekday" => 7 - expect(provider.content?).to be_truthy - expect(provider.content).to eql(test_plist) + expect(provider.file_content?).to be_truthy + expect(provider.file_content).to eql(test_plist) end end @@ -147,8 +147,8 @@ describe Chef::Provider::Launchd do new_resource.program "/Library/scripts/call_mom.sh" new_resource.time_out 300 new_resource.start_calendar_interval allowed - expect(provider.content?).to be_truthy - expect(provider.content).to eql(test_plist_multiple_intervals) + expect(provider.file_content?).to be_truthy + expect(provider.file_content).to eql(test_plist_multiple_intervals) end it "should allow all StartCalendarInterval keys" do @@ -162,9 +162,9 @@ describe Chef::Provider::Launchd do new_resource.program "/Library/scripts/call_mom.sh" new_resource.time_out 300 new_resource.start_calendar_interval allowed - expect(provider.content?).to be_truthy + expect(provider.file_content?).to be_truthy %w{Minute Hour Day Weekday Month}.each do |key| - expect(provider.content).to include("<key>#{key}</key>") + expect(provider.file_content).to include("<key>#{key}</key>") end end @@ -188,8 +188,8 @@ describe Chef::Provider::Launchd do describe "hash is passed" do it "should produce the test_plist content from the plist_hash property" do new_resource.plist_hash test_hash - expect(provider.content?).to be_truthy - expect(provider.content).to eql(test_plist) + expect(provider.file_content?).to be_truthy + expect(provider.file_content).to eql(test_plist) end end end |