diff options
author | kaustubh-d <kausubh@clogeny.com> | 2013-07-22 01:28:18 -0700 |
---|---|---|
committer | adamedx <adamed@opscode.com> | 2013-08-04 08:27:07 -0700 |
commit | 22c645821fda39f1e2d1fe21e9b22917f5ff513c (patch) | |
tree | 4eae03a90fb41ffc9aca3dbeeddede0490c9cff0 | |
parent | cc0f7bbfc0d293098e97b7cb26f5c5d762ed0304 (diff) | |
download | chef-22c645821fda39f1e2d1fe21e9b22917f5ff513c.tar.gz |
abstract cron entry creation and reset @cron_exists on load.
-rw-r--r-- | lib/chef/provider/cron.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/chef/provider/cron.rb b/lib/chef/provider/cron.rb index a7218fea5a..19fe9a64af 100644 --- a/lib/chef/provider/cron.rb +++ b/lib/chef/provider/cron.rb @@ -45,6 +45,7 @@ class Chef crontab_lines = [] @current_resource = Chef::Resource::Cron.new(@new_resource.name) @current_resource.user(@new_resource.user) + @cron_exists = false if crontab = read_crontab cron_found = false crontab.each_line do |line| @@ -93,14 +94,7 @@ class Chef newcron = String.new cron_found = false - newcron << "# Chef Name: #{new_resource.name}\n" - [ :mailto, :path, :shell, :home ].each do |v| - newcron << "#{v.to_s.upcase}=#{@new_resource.send(v)}\n" if @new_resource.send(v) - end - @new_resource.environment.each do |name, value| - newcron << "#{name}=#{value}\n" - end - newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n" + newcron = get_crontab_entry if @cron_exists unless cron_different? @@ -209,6 +203,19 @@ class Chef raise Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: #{status.exitstatus}" end end + + def get_crontab_entry + newcron = "" + newcron << "# Chef Name: #{new_resource.name}\n" + [ :mailto, :path, :shell, :home ].each do |v| + newcron << "#{v.to_s.upcase}=#{@new_resource.send(v)}\n" if @new_resource.send(v) + end + @new_resource.environment.each do |name, value| + newcron << "#{name}=#{value}\n" + end + newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n" + newcron + end end end end |