Commit aaa75ede authored by Tim Smith's avatar Tim Smith
Browse files

Add a name_property if you want a more descriptive resource name


Signed-off-by: default avatarTim Smith <tsmith@chef.io>
parent 107fd11f
......@@ -30,6 +30,7 @@ The `cron_d` custom resource can be used to manage files in `/etc/cron.d`. It su
#### Properties
- `cron_name` - Set the name of the cron job. If this isn't specified we'll use the resource name.
- `minute`, `hour`, `day`, `month`, `weekday` - schedule your cron job. These correspond exactly to their equivalents in the crontab file. All default to "*".
- `predefined_value` - schedule your cron job with one of the special predefined value instead of _**_ * pattern. This correspond to `"@reboot"`, `"@yearly"`, `"@annually"`, `"@monthly"`, `"@weekly"`, `"@daily"`, `"@midnight"` or `"@hourly"`.
- `command` - the command to run. Required.
......@@ -49,6 +50,16 @@ cron_d 'daily-usage-report' do
end
```
```ruby
cron_d 'Setup the daily usage cron job' do
cron_name 'daily-usage-report'
minute 0
hour 23
command '/srv/app/scripts/daily_report'
user 'appuser'
end
```
## Definitions
### `cron_manage`
......
......@@ -19,6 +19,7 @@
require 'shellwords'
property :cron_name, name_property: true
property :cookbook, String, default: 'cron'
property :predefined_value, String, equal_to: %w( @reboot @yearly @annually @monthly @weekly @daily @midnight @hourly )
property :minute, [Integer, String], default: '*', callbacks: {
......@@ -60,7 +61,7 @@ end
action :delete do
# cleanup the legacy named job if it exists
file 'legacy named cron.d file' do
path "/etc/cron.d/#{new_resource.name}"
path "/etc/cron.d/#{new_resource.cron_name}"
action :delete
end
......@@ -71,15 +72,15 @@ end
action_class do
def sanitized_name
new_resource.name.tr('.', '-')
new_resource.cron_name.tr('.', '-')
end
def create_template(create_action)
# cleanup the legacy named job if it exists
file "#{new_resource.name} legacy named cron.d file" do
path "/etc/cron.d/#{new_resource.name}"
file "#{new_resource.cron_name} legacy named cron.d file" do
path "/etc/cron.d/#{new_resource.cron_name}"
action :delete
only_if { new_resource.name != sanitized_name }
only_if { new_resource.cron_name != sanitized_name }
end
template "/etc/cron.d/#{sanitized_name}" do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment