Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ It allows specifying the following parameters:
* user
* command
* environment
* comment

Example:
This would run the command "mysqldump -u root mydb" as root at 2:40 AM every day:
Expand All @@ -55,7 +56,8 @@ Example:
weekday => '*',
user => 'root',
command => 'mysqldump -u root mydb',
environment => [ 'MAILTO=root', 'PATH="/usr/bin:/bin"' ];
environment => [ 'MAILTO=root', 'PATH="/usr/bin:/bin"' ],
comment => 'This job updates so and so then copies this to that',
}

### cron::hourly
Expand All @@ -68,6 +70,7 @@ It allows specifying the following parameters:
* user
* command
* environment
* comment

Example:
This would run the command "mysqldump -u root mydb" as root on the 20th minute of every hour:
Expand All @@ -78,6 +81,7 @@ Example:
user => 'root',
command => 'mysqldump -u root mydb',
environment => "MAILTO=root\nPATH='/usr/bin:/bin'";
comment => 'This job updates so and so then copies this to that',
}

### cron::daily
Expand All @@ -91,6 +95,7 @@ It allows specifying the following parameters:
* user
* command
* environment
* comment

Example:
This would run the command "mysqldump -u root mydb" as root at 2:40 AM every day, like the above generic example:
Expand All @@ -101,6 +106,7 @@ Example:
hour => '2',
user => 'root',
command => 'mysqldump -u root mydb';
comment => 'This job updates so and so then copies this to that',
}

### cron::weekly
Expand All @@ -115,6 +121,7 @@ It allows specifying the following parameters:
* user
* command
* environment
* comment

Example:
This would run the command "mysqldump -u root mydb" as root at 4:40 AM every Sunday, like the above generic example:
Expand All @@ -126,6 +133,7 @@ Example:
weekday => '0',
user => 'root',
command => 'mysqldump -u root mydb';
comment => 'This job updates so and so then copies this to that',
}

### cron::monthly
Expand All @@ -140,6 +148,7 @@ It allows specifying the following parameters:
* user
* command
* environment
* comment

Example:
This would run the command "mysqldump -u root mydb" as root at 3:40 AM the 1st of every month, like the above generic example:
Expand All @@ -151,6 +160,7 @@ Example:
date => '1',
user => 'root',
command => 'mysqldump -u root mydb';
comment => 'This job updates so and so then copies this to that',
}

## Contributors:
Expand Down
7 changes: 5 additions & 2 deletions manifests/daily.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# Defaults to 0644.
# command - The command to execute.
# Defaults to undef.
# comment - Optional comment to add to the crontab file
# Defaults to undef
#
# Actions:
#
Expand All @@ -33,7 +35,7 @@

define cron::daily(
$command = undef, $minute = 0, $hour = 0, $environment = [],
$user = 'root', $mode = '0644', $ensure = 'present'
$user = 'root', $mode = '0644', $ensure = 'present', $comment = undef,
){
cron::job {
$title:
Expand All @@ -46,7 +48,8 @@
user => $user,
environment => $environment,
mode => $mode,
command => $command;
command => $command,
comment => $comment,
}
}

7 changes: 5 additions & 2 deletions manifests/hourly.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# Defaults to 'root'.
# command - The command to execute.
# Defaults to undef.
# comment - Optional comment to add to the crontab file
# Defaults to undef
#
# Actions:
#
Expand All @@ -28,7 +30,7 @@
# command => 'puppet doc --modulepath /etc/puppet/modules >/var/www/puppet_docs.mkd';
# }
define cron::hourly(
$command = undef, $minute = 0, $environment = [],
$command = undef, $minute = 0, $environment = [], $comment = undef,
$user = 'root', $mode = '0644', $ensure = 'present'
) {
cron::job {
Expand All @@ -42,7 +44,8 @@
user => $user,
environment => $environment,
mode => $mode,
command => $command;
command => $command,
comment => $comment,
}
}

4 changes: 3 additions & 1 deletion manifests/job.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# Defaults to 'root'.
# command - The command to execute.
# Defaults to undef.
# comment - Optional comment to add to the crontab file
# Defaults to undef
#
# Actions:
#
Expand All @@ -37,7 +39,7 @@
# }
define cron::job(
$command = undef, $minute = '*', $hour = '*', $date = '*', $month = '*', $weekday = '*',
$environment = [], $user = 'root', $mode = '0644', $ensure = 'present'
$environment = [], $user = 'root', $mode = '0644', $ensure = 'present', $comment = undef,
) {

case $ensure {
Expand Down
7 changes: 5 additions & 2 deletions manifests/monthly.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# Defaults to 0644.
# command - The command to execute.
# Defaults to undef.
# comment - Optional comment to add to the crontab file
# Defaults to undef
#
# Actions:
#
Expand All @@ -35,7 +37,7 @@
# }

define cron::monthly(
$command = undef, $minute = 0, $hour = 0, $date = 1,
$command = undef, $minute = 0, $hour = 0, $date = 1, $comment = undef,
$environment = [], $user = 'root', $mode = '0644', $ensure = 'present'
) {
cron::job {
Expand All @@ -49,7 +51,8 @@
user => $user,
environment => $environment,
mode => $mode,
command => $command;
command => $command,
comment => $comment,
}
}

7 changes: 5 additions & 2 deletions manifests/weekly.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# Defaults to '0640'.
# command - The command to execute.
# Defaults to undef.
# comment - Optional comment to add to the crontab file
# Defaults to undef
#
# Actions:
#
Expand All @@ -36,7 +38,7 @@

define cron::weekly(
$command = undef, $minute = 0, $hour = 0, $weekday = 0, $user = 'root',
$mode = '0640', $ensure = 'present', $environment = []
$mode = '0640', $ensure = 'present', $environment = [], $comment = undef,
) {
cron::job {
$title:
Expand All @@ -49,7 +51,8 @@
user => $user,
environment => $environment,
mode => $mode,
command => $command;
command => $command,
comment => $comment,
}
}

6 changes: 4 additions & 2 deletions spec/defines/daily_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
let( :params ) {{
:minute => '59',
:hour => '1',
:command => 'mysqldump -u root test_db >some_file'
:command => 'mysqldump -u root test_db >some_file',
:comment => 'do this'
}}

it do
Expand All @@ -18,7 +19,8 @@
'user' => params[:user] || 'root',
'environment' => params[:environment] || [],
'mode' => params[:mode] || '0644',
'command' => params[:command]
'command' => params[:command],
'comment' => params[:comment]
)
end
end
Expand Down
6 changes: 4 additions & 2 deletions spec/defines/hourly_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
let( :title ) { 'mysql_backup' }
let( :params ) {{
:minute => '59',
:command => 'mysqldump -u root test_db >some_file'
:command => 'mysqldump -u root test_db >some_file',
:comment => 'do this'
}}

it do
Expand All @@ -17,7 +18,8 @@
'user' => params[:user] || 'root',
'environment' => params[:environment] || [],
'mode' => params[:mode] || '0644',
'command' => params[:command]
'command' => params[:command],
'comment' => params[:comment]
)
end
end
Expand Down
3 changes: 3 additions & 0 deletions spec/defines/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
:user => 'admin',
:mode => '0640',
:command => 'mysqldump -u root test_db >some_file',
:comment => 'do this'
}}
let( :cron_timestamp ) { get_timestamp( params ) }

Expand All @@ -48,6 +49,8 @@
/\s+#{params[:user]}\s+/
).with_content(
/\s+#{params[:command]}\n/
).with_content(
/\s+#{params[:comment]}\n/
)
end
end
Expand Down
6 changes: 4 additions & 2 deletions spec/defines/monthly_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
:minute => '59',
:hour => '1',
:date => '20',
:command => 'mysqldump -u root test_db >some_file'
:command => 'mysqldump -u root test_db >some_file',
:comment => 'do this'
}}

it do
Expand All @@ -19,7 +20,8 @@
'user' => params[:user] || 'root',
'environment' => params[:environment] || [],
'mode' => params[:mode] || '0644',
'command' => params[:command]
'command' => params[:command],
'comment' => params[:comment]
)
end
end
Expand Down
6 changes: 4 additions & 2 deletions spec/defines/weekly_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
:minute => '59',
:hour => '1',
:weekday => '2',
:command => 'mysqldump -u root test_db >some_file'
:command => 'mysqldump -u root test_db >some_file',
:comment => 'do this'
}}

it do
Expand All @@ -19,7 +20,8 @@
'user' => params[:user] || 'root',
'environment' => params[:environment] || [],
'mode' => params[:mode] || '0640',
'command' => params[:command]
'command' => params[:command],
'comment' => params[:comment]
)
end
end
Expand Down
5 changes: 5 additions & 0 deletions templates/job.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
### This file is managed by puppet, and is refreshed regularly. Edit at your own peril! ###
###########################################################################################
## <%= @name %> Cron Job
<%- if @comment -%>
##
## <%= @comment %>
##
<%- end -%>

# Environment Settings
<% Array(@environment).join("\n").split(%r{\n}).each do |env_var|
Expand Down