From ec09e63ec43f7a9674ee657ab7a1707f0e139c73 Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Tue, 9 Mar 2021 11:26:56 -0800 Subject: use full path for launchctl calls Signed-off-by: Jeff Johnson --- lib/chef/provider/service/macosx.rb | 6 +++--- lib/chef/resource/chef_client_launchd.rb | 2 +- spec/unit/provider/service/macosx_spec.rb | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb index 2152789a6e..206c67e277 100644 --- a/lib/chef/provider/service/macosx.rb +++ b/lib/chef/provider/service/macosx.rb @@ -169,12 +169,12 @@ class Chef def load_service session = @session_type ? "-S #{@session_type} " : "" - cmd = "launchctl load -w " + session + @plist + cmd = "/bin/launchctl load -w " + session + @plist shell_out_as_user(cmd) end def unload_service - cmd = "launchctl unload -w " + @plist + cmd = "/bin/launchctl unload -w " + @plist shell_out_as_user(cmd) end @@ -190,7 +190,7 @@ class Chef def set_service_status return if @plist.nil? || @service_label.to_s.empty? - cmd = "launchctl list #{@service_label}" + cmd = "/bin/launchctl list #{@service_label}" res = shell_out_as_user(cmd) if res.exitstatus == 0 diff --git a/lib/chef/resource/chef_client_launchd.rb b/lib/chef/resource/chef_client_launchd.rb index 0e173050d0..9450c760a0 100644 --- a/lib/chef/resource/chef_client_launchd.rb +++ b/lib/chef/resource/chef_client_launchd.rb @@ -134,7 +134,7 @@ class Chef standard_error_path ::File.join(new_resource.log_directory, new_resource.log_file_name) program_arguments ["/bin/bash", "-c", - "echo; echo #{ChefUtils::Dist::Infra::PRODUCT} launchd daemon config has been updated. Manually unloading and reloading the daemon; echo Now unloading the daemon; launchctl unload /Library/LaunchDaemons/com.#{ChefUtils::Dist::Infra::SHORT}.#{ChefUtils::Dist::Infra::CLIENT}.plist; sleep 2; echo Now loading the daemon; launchctl load /Library/LaunchDaemons/com.#{ChefUtils::Dist::Infra::SHORT}.#{ChefUtils::Dist::Infra::CLIENT}.plist"] + "echo; echo #{ChefUtils::Dist::Infra::PRODUCT} launchd daemon config has been updated. Manually unloading and reloading the daemon; echo Now unloading the daemon; /bin/launchctl unload /Library/LaunchDaemons/com.#{ChefUtils::Dist::Infra::SHORT}.#{ChefUtils::Dist::Infra::CLIENT}.plist; sleep 2; echo Now loading the daemon; /bin/launchctl load /Library/LaunchDaemons/com.#{ChefUtils::Dist::Infra::SHORT}.#{ChefUtils::Dist::Infra::CLIENT}.plist"] action :enable # enable creates the plist & triggers service restarts on change end diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 6cc0f88725..6b86265a04 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -78,7 +78,7 @@ describe Chef::Provider::Service::Macosx do @getpwuid = double("Etc::Passwd", { name: "mikedodge04" }) allow(Etc).to receive(:getpwuid).and_return(@getpwuid) allow(node).to receive(:[]).with("platform_version").and_return("10.11.1") - cmd = "launchctl list #{service_label}" + cmd = "/bin/launchctl list #{service_label}" allow(provider).to receive(:shell_out) .with(/(#{su_cmd} '#{cmd}'|#{cmd})/, default_env: false) .and_return(double("Status", @@ -265,7 +265,7 @@ describe Chef::Provider::Service::Macosx do end it "starts service via launchctl if service found" do - cmd = "launchctl load -w " + session + plist + cmd = "/bin/launchctl load -w " + session + plist expect(provider).to receive(:shell_out) .with(/(#{su_cmd} .#{cmd}.|#{cmd})/, default_env: false) .and_return(0) @@ -297,7 +297,7 @@ describe Chef::Provider::Service::Macosx do end it "stops the service via launchctl if service found" do - cmd = "launchctl unload -w " + plist + cmd = "/bin/launchctl unload -w " + plist expect(provider).to receive(:shell_out) .with(/(#{su_cmd} .#{cmd}.|#{cmd})/, default_env: false) .and_return(0) -- cgit v1.2.1