Skip to content

Commit

Permalink
Merge branch 'master' of github.com:roman-mueller/puppet-cron
Browse files Browse the repository at this point in the history
roman-mueller committed Mar 19, 2016
2 parents 3066e87 + 4f4411d commit b11b9c1
Showing 9 changed files with 55 additions and 8 deletions.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ It allows specifying the following parameters:
* `user` - optional - defaults to "root"
* `environment` - optional - defaults to ""
* `mode` - optional - defaults to "0644"
* `description` - optional - defaults to undef

Example:
This would create the file `/etc/cron.d/mysqlbackup` and run the command `mysqldump -u root mydb` as root at 2:40 AM every day:
@@ -83,6 +84,7 @@ This would create the file `/etc/cron.d/mysqlbackup` and run the command `mysqld
user => 'root',
command => 'mysqldump -u root mydb',
environment => [ 'MAILTO=root', 'PATH="/usr/bin:/bin"', ],
description => 'Mysql backup',
}

Hiera example:
@@ -101,6 +103,7 @@ cron::job:
environment:
- 'MAILTO=root'
- 'PATH="/usr/bin:/bin"'
description: 'Mysql backup'
```
### cron::job::multiple
@@ -115,13 +118,14 @@ It allows specifiying the following parameters:

And parameters of the jobs hash are:

* `command` - required - the command to execute
* `minute` - optional - defaults to "\*"
* `hour` - optional - defaults to "\*"
* `date` - optional - defaults to "\*"
* `month` - optional - defaults to "\*"
* `weekday` - optional - defaults to "\*"
* `user` - optional - defaults to "root"
* `command` - required - the command to execute
* `minute` - optional - defaults to "\*"
* `hour` - optional - defaults to "\*"
* `date` - optional - defaults to "\*"
* `month` - optional - defaults to "\*"
* `weekday` - optional - defaults to "\*"
* `user` - optional - defaults to "root"
* `description` - optional - defaults to undef

Example:

@@ -136,9 +140,11 @@ cron::job::multiple { 'test_cron_job_multiple':
weekday => '*',
user => 'rmueller',
command => '/usr/bin/uname',
description => 'print system information',
},
{
command => '/usr/bin/sleep 1',
description => 'Sleeping',
},
],
environment => [ 'PATH="/usr/sbin:/usr/bin:/sbin:/bin"' ],
@@ -161,9 +167,11 @@ cron::job::multiple:
weekday: '*',
user: rmueller,
command: '/usr/bin/uname',
description: 'print system information',
}
- {
command: '/usr/bin/sleep 1',
description: 'Sleeping',
}
environment:
@@ -190,6 +198,7 @@ It allows specifying the following parameters:
* `user` - optional - defaults to "root"
* `environment` - optional - defaults to ""
* `mode` - optional - defaults to "0644"
* `description` - optional - defaults to undef

Example:
This would create the file `/etc/cron.d/mysqlbackup_hourly` and run the command `mysqldump -u root mydb` as root on the 20th minute of every hour:
@@ -227,6 +236,7 @@ It allows specifying the following parameters:
* `user` - optional - defaults to "root"
* `environment` - optional - defaults to ""
* `mode` - optional - defaults to "0644"
* `description` - optional - defaults to undef

Example:
This would create the file `/etc/cron.d/mysqlbackup_daily` and run the command `mysqldump -u root mydb` as root at 2:40 AM every day, like the above generic example:
@@ -264,6 +274,7 @@ It allows specifying the following parameters:
* `user` - optional - defaults to "root"
* `environment` - optional - defaults to ""
* `mode` - optional - defaults to "0644"
* `description` - optional - defaults to undef

Example:
This would create the file `/etc/cron.d/mysqlbackup_weekly` and run the command `mysqldump -u root mydb` as root at 4:40 AM every Sunday, like the above generic example:
@@ -303,6 +314,7 @@ It allows specifying the following parameters:
* `user` - optional - defaults to "root"
* `environment` - optional - defaults to ""
* `mode` - optional - defaults to "0644"
* `description` - optional - defaults to undef

Example:
This would create the file `/etc/cron.d/mysqlbackup_monthly` and run the command `mysqldump -u root mydb` as root at 3:40 AM the 1st of every month, like the above generic example:
5 changes: 5 additions & 0 deletions manifests/daily.pp
Original file line number Diff line number Diff line change
@@ -17,6 +17,9 @@
# Defaults to 'root'.
# mode - The mode to set on the created job file
# Defaults to 0644.
# description - Optional short description, which will be included in the
# cron job file.
# Defaults to undef.
# command - The command to execute.
#
# Actions:
@@ -39,6 +42,7 @@
$environment = [],
$user = 'root',
$mode = '0644',
$description = undef,
) {

cron::job { $title:
@@ -52,6 +56,7 @@
environment => $environment,
mode => $mode,
command => $command,
description => $description,
}

}
8 changes: 7 additions & 1 deletion manifests/hourly.pp
Original file line number Diff line number Diff line change
@@ -12,7 +12,11 @@
# Defaults to an empty set ([]).
# mode - The mode to set on the created job file.
# Defaults to 0644.
# user - The user the cron job should be executed as. Defaults to 'root'.
# user - The user the cron job should be executed as.
# Defaults to 'root'.
# description - Optional short description, which will be included in the
# cron job file.
# Defaults to undef.
# command - The command to execute.
#
# Actions:
@@ -33,6 +37,7 @@
$environment = [],
$user = 'root',
$mode = '0644',
$description = undef,
) {

cron::job { $title:
@@ -46,6 +51,7 @@
environment => $environment,
mode => $mode,
command => $command,
description => $description,
}

}
4 changes: 4 additions & 0 deletions manifests/job.pp
Original file line number Diff line number Diff line change
@@ -26,6 +26,9 @@
# Defaults to 0644.
# user - The user the cron job should be executed as.
# Defaults to 'root'.
# description - Optional short description, which will be included in the
# cron job file.
# Defaults to undef.
# command - The command to execute.
#
# Actions:
@@ -50,6 +53,7 @@
$environment = [],
$user = 'root',
$mode = '0644',
$description = undef,
) {

case $ensure {
5 changes: 5 additions & 0 deletions manifests/monthly.pp
Original file line number Diff line number Diff line change
@@ -20,6 +20,9 @@
# Defaults to 'root'.
# mode - The mode to set on the created job file
# Defaults to 0644.
# description - Optional short description, which will be included in the
# cron job file.
# Defaults to undef.
# command - The command to execute.
#
# Actions:
@@ -44,6 +47,7 @@
$environment = [],
$user = 'root',
$mode = '0644',
$description = undef,
) {

cron::job { $title:
@@ -57,6 +61,7 @@
environment => $environment,
mode => $mode,
command => $command,
description => $description,
}

}
5 changes: 5 additions & 0 deletions manifests/weekly.pp
Original file line number Diff line number Diff line change
@@ -20,6 +20,9 @@
# Defaults to 'root'.
# mode - The mode to set on the created job file
# Defaults to '0640'.
# description - Optional short description, which will be included in the
# cron job file.
# Defaults to undef.
# command - The command to execute.
#
# Actions:
@@ -44,6 +47,7 @@
$user = 'root',
$mode = '0640',
$environment = [],
$description = undef,
) {

cron::job { $title:
@@ -57,6 +61,7 @@
environment => $environment,
mode => $mode,
command => $command,
description => $description,
}

}
3 changes: 3 additions & 0 deletions spec/defines/job_spec.rb
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
:environment => [ 'MAILTO="root"', 'PATH="/usr/sbin:/usr/bin:/sbin:/bin"' ],
:user => 'admin',
:mode => '0640',
:description => 'Mysql backup',
:command => 'mysqldump -u root test_db >some_file',
}}
let( :cron_timestamp ) { get_timestamp( params ) }
@@ -48,6 +49,8 @@
/\s+#{params[:user]}\s+/
).with_content(
/\s+#{params[:command]}\n/
).with_content(
/\n# #{params[:description]}\n/
)
end
end
3 changes: 3 additions & 0 deletions templates/job.erb
Original file line number Diff line number Diff line change
@@ -14,5 +14,8 @@
end -%>

# Job Definition
<% if @description -%>
# <%= @description %>
<% end -%>
<%= @minute %> <%= @hour %> <%= @date %> <%= @month %> <%= @weekday %> <%= @user %> <%= @command %>

4 changes: 4 additions & 0 deletions templates/multiple.erb
Original file line number Diff line number Diff line change
@@ -35,5 +35,9 @@
<%- if job['user'].nil? -%>
<%- job['user'] = 'root' -%>
<%- end -%>
<% if job.has_key?('description') -%>

# <%= job['description'] %>
<% end -%>
<%= job['minute'] %> <%= job['hour'] %> <%= job['date'] %> <%= job['month'] %> <%= job['weekday'] %> <%= job['user'] %> <%= job['command'] %>
<% end -%>

0 comments on commit b11b9c1

Please sign in to comment.