Skip to content

Commit

Permalink
Add cron_before_command (voxpupuli#48)
Browse files Browse the repository at this point in the history
* Add cron_before_command

* Fix lint errors

* Fix rubocop offenses
  • Loading branch information
gkopylov authored and jyaworski committed Jan 1, 2017
1 parent ca87541 commit bf8f5f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change log
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]
- Ability to run commands before a cronjob-based renewal with the `cron_before_command` parameter.

## 2016-12-22 Release 1.0.1
- Ability to run commands after a successful cronjob-based renewal with the `cron_success_command` parameter.
- Modulesync with latest Vox Pupuli defaults
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ letsencrypt::certonly { 'foo':

To automatically renew a certificate, you can pass the `manage_cron` parameter.
You can optionally add a shell command to be run on success using the `cron_success_command` parameter.
You can optionally add a shell command to be run on before using the `cron_before_command` parameter.

```puppet
letsencrypt::certonly { 'foo':
domains => ['foo.example.com', 'bar.example.com'],
manage_cron => true,
cron_before_command => 'service nginx stop',
cron_success_command => '/bin/systemctl reload nginx.service',
}
```
Expand Down
10 changes: 9 additions & 1 deletion manifests/certonly.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# [*manage_cron*]
# Boolean indicating whether or not to schedule cron job for renewal.
# Runs daily but only renews if near expiration, e.g. within 10 days.
# [*cron_before_command*]
# String representation of a command that should be run before renewal command
# [*cron_success_command*]
# String representation of a command that should be run if the renewal command
# succeeds.
Expand All @@ -36,6 +38,7 @@
$additional_args = undef,
$environment = [],
$manage_cron = false,
$cron_before_command = undef,
$cron_success_command = undef,
) {
validate_array($domains)
Expand Down Expand Up @@ -71,7 +74,12 @@
}

if $manage_cron {
$renewcommand = "${command_start}--keep-until-expiring ${command_domains}${command_end}"
$maincommand = "${command_start}--keep-until-expiring ${command_domains}${command_end}"
if $cron_before_command {
$renewcommand = "(${cron_before_command}) && ${maincommand}"
} else {
$renewcommand = $maincommand
}
if $cron_success_command {
$cron_cmd = "${renewcommand} && (${cron_success_command})"
} else {
Expand Down
3 changes: 2 additions & 1 deletion spec/defines/letsencrypt_certonly_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@
let(:params) do
{ plugin: 'apache',
manage_cron: true,
cron_before_command: 'echo before',
cron_success_command: 'echo success' }
end
it { is_expected.to contain_cron('letsencrypt renew cron foo.example.com').with_command 'letsencrypt --agree-tos certonly -a apache --keep-until-expiring -d foo.example.com && (echo success)' }
it { is_expected.to contain_cron('letsencrypt renew cron foo.example.com').with_command '(echo before) && letsencrypt --agree-tos certonly -a apache --keep-until-expiring -d foo.example.com && (echo success)' }
end

context 'with invalid plugin' do
Expand Down

0 comments on commit bf8f5f5

Please sign in to comment.