summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaustubh-d <kaustubh@clogeny.com>2013-07-30 14:31:41 +0530
committeradamedx <adamed@opscode.com>2013-08-04 08:27:07 -0700
commitbd547c7d8025e0daef0b9220f48d6079071dbab4 (patch)
tree981968f5160bf4f06e42d2941a1552569627d91a
parentb0e12a56e1e31748aa9c6519e79fdd7e40d752d8 (diff)
downloadchef-bd547c7d8025e0daef0b9220f48d6079071dbab4.tar.gz
solaris9, 10 on some failures for example invalid mins in crontab fails with exit code of zero
-rw-r--r--lib/chef/mixin/command.rb17
-rw-r--r--lib/chef/provider/cron/unix.rb7
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