diff options
-rw-r--r-- | lib/chef/mixin/command.rb | 17 | ||||
-rw-r--r-- | lib/chef/provider/cron/unix.rb | 7 |
2 files changed, 19 insertions, 5 deletions
diff --git a/lib/chef/mixin/command.rb b/lib/chef/mixin/command.rb index 55c028ff5f..719151a6b6 100644 --- a/lib/chef/mixin/command.rb +++ b/lib/chef/mixin/command.rb @@ -56,8 +56,17 @@ class Chef # === Returns # Returns the exit status of args[:command] def run_command(args={}) - command_output = "" + status, stdout, stderr = run_command_and_return_stdout_stderr(args) + status + end + + # works same as above, except that it returns stdout and stderr + # requirement => platforms like solaris 9,10 has wierd issues where + # even in command failure the exit code is zero, so we need to lookup stderr. + def run_command_and_return_stdout_stderr(args={}) + command_output = "" + args[:ignore_failure] ||= false args[:output_on_failure] ||= false @@ -73,10 +82,10 @@ class Chef command_output << "STDOUT: #{stdout}" command_output << "STDERR: #{stderr}" handle_command_failures(status, command_output, args) - - status + + return status, stdout, stderr end - + def output_of_command(command, args) Chef::Log.debug("Executing #{command}") stderr_string, stdout_string, status = "", "", nil diff --git a/lib/chef/provider/cron/unix.rb b/lib/chef/provider/cron/unix.rb index 017a9f12ca..91df12d213 100644 --- a/lib/chef/provider/cron/unix.rb +++ b/lib/chef/provider/cron/unix.rb @@ -47,8 +47,13 @@ class Chef exit_status = 0 error_message = "" begin - status = run_command(:command => "/usr/bin/crontab #{tempcron.path}",:user => @new_resource.user) + status, stdout, stderr = run_command_and_return_stdout_stderr(:command => "/usr/bin/crontab #{tempcron.path}",:user => @new_resource.user) exit_status = status.exitstatus + # solaris9, 10 on some failures for example invalid 'mins' in crontab fails with exit code of zero :( + if stderr.include?("errors detected in input, no crontab file generated") + error_message = stderr + exit_status = 1 + end rescue Chef::Exceptions::Exec => e Chef::Log.debug(e.message) exit_status = 1 |