diff options
author | Juri Timoshin <juri.timoshin@zeroturnaround.com> | 2013-08-31 18:22:53 +0300 |
---|---|---|
committer | Bryan McLellan <btm@getchef.com> | 2014-03-20 13:06:29 -0700 |
commit | 91fd0a3190cba3409a67659acfd9dc44bb6f0000 (patch) | |
tree | 6c42c278ea405688e85feb73ff04a985eae99267 /lib/chef/provider/cron.rb | |
parent | fb9391b81a3eeceff9c730a975a8583ae43fe048 (diff) | |
download | chef-91fd0a3190cba3409a67659acfd9dc44bb6f0000.tar.gz |
Enabled using special strings in cron. CHEF-2816
Diffstat (limited to 'lib/chef/provider/cron.rb')
-rw-r--r-- | lib/chef/provider/cron.rb | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/chef/provider/cron.rb b/lib/chef/provider/cron.rb index e80f70d8bb..1be15f9f5f 100644 --- a/lib/chef/provider/cron.rb +++ b/lib/chef/provider/cron.rb @@ -25,12 +25,14 @@ class Chef class Cron < Chef::Provider include Chef::Mixin::Command + SPECIAL_TIME_VALUES = [:reboot, :yearly, :annually, :monthly, :weekly, :daily, :midnight, :hourly] + CRON_ATTRIBUTES = [:minute, :hour, :day, :month, :weekday, :time, :command, :mailto, :path, :shell, :home, :environment] + WEEKDAY_SYMBOLS = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday] + CRON_PATTERN = /\A([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+|[a-zA-Z]{3})\s([-0-9*,\/]+|[a-zA-Z]{3})\s(.*)/ + SPECIAL_PATTERN = /\A(@(#{SPECIAL_TIME_VALUES.join('|')}))\s(.*)/ ENV_PATTERN = /\A(\S+)=(\S*)/ - CRON_ATTRIBUTES = [:minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home, :environment] - WEEKDAY_SYMBOLS = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday] - def initialize(new_resource, run_context) super(new_resource, run_context) @cron_exists = false @@ -59,6 +61,12 @@ class Chef when ENV_PATTERN set_environment_var($1, $2) if cron_found next + when SPECIAL_PATTERN + if cron_found + @current_resource.time($2.to_sym) + @current_resource.command($3) + cron_found=false + end when CRON_PATTERN if cron_found @current_resource.minute($1) @@ -221,7 +229,11 @@ class Chef @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} #{weekday_in_crontab} #{@new_resource.command}\n" + if @new_resource.time + newcron << "@#{@new_resource.time} #{@new_resource.command}\n" + else + newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n" + end newcron end |