summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJuri Timoshin <juri.timoshin@zeroturnaround.com>2013-08-31 18:22:53 +0300
committerBryan McLellan <btm@getchef.com>2014-03-20 13:06:29 -0700
commit91fd0a3190cba3409a67659acfd9dc44bb6f0000 (patch)
tree6c42c278ea405688e85feb73ff04a985eae99267 /lib
parentfb9391b81a3eeceff9c730a975a8583ae43fe048 (diff)
downloadchef-91fd0a3190cba3409a67659acfd9dc44bb6f0000.tar.gz
Enabled using special strings in cron. CHEF-2816
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/provider/cron.rb20
-rw-r--r--lib/chef/resource/cron.rb9
2 files changed, 25 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
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb
index be70c8b5a0..9c04658bf3 100644
--- a/lib/chef/resource/cron.rb
+++ b/lib/chef/resource/cron.rb
@@ -43,6 +43,7 @@ class Chef
@path = nil
@shell = nil
@home = nil
+ @time = nil
@environment = {}
end
@@ -137,6 +138,14 @@ class Chef
:kind_of => [String, Symbol]
)
end
+
+ def time(arg=nil)
+ set_or_return(
+ :time,
+ arg,
+ :equal_to => Chef::Provider::Cron::SPECIAL_TIME_VALUES
+ )
+ end
def mailto(arg=nil)
set_or_return(