Skip to content

Commit

Permalink
Merge branch '2.0.0' into 2.0.0_release_prep
Browse files Browse the repository at this point in the history
  • Loading branch information
davejrt authored Jul 18, 2018
2 parents 634b350 + 2eafbbc commit 12fdd37
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Version 2.2.0
# Version 2.0.0

Various fixes for github issues
- 193
Expand Down Expand Up @@ -129,4 +129,4 @@ Forked for garethr/docker v5.3.0
Added support for:
- Docker services within a swarm cluster
- Swarm mode
- Docker secrets
- Docker secrets
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,15 @@ docker::run { 'helloworld':
}
```

To enable the restart of an unhealthy container add the following code to the manifest file.
To enable the restart of an unhealthy container add the following code to the manifest file.In order to set the health check interval time set the optional health_check_interval parameter, the default health check interval is 30 seconds.

```puppet
docker::run { 'helloworld':
image => 'base',
command => 'command',
health_check_command => '<command_to_execute_to_check_your_containers_health>',
health_check_cmd => '<command_to_execute_to_check_your_containers_health>',
restart_on_unhealthy => true,
health_check_interval => '<time between running docker healthcheck>',
```

To run command on Windows 2016 requires the `restart` parameter to be set:
Expand Down
6 changes: 5 additions & 1 deletion lib/puppet/parser/functions/docker_run_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ module Puppet::Parser::Functions
end

if opts['health_check_cmd'].to_s != 'undef'
flags << "--health-cmd #{opts['health_check_cmd']}"
flags << "--health-cmd='#{opts['health_check_cmd']}'"
end

if opts['health_check_interval'].to_s != 'undef'
flags << "--health-interval=#{opts['health_check_interval']}s"
end

if opts['tty']
Expand Down
14 changes: 10 additions & 4 deletions manifests/run.pp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
# (optional) Specifies the command to execute to check that the container is healthy using the docker health check functionality.
# Default: undef
#
# [*health_check_interval*]
# (optional) Specifies the interval that the health check command will execute in seconds.
# Default: undef
#
# [*restart_on_unhealthy*]
# (optional) Checks the health status of Docker container and if it is unhealthy the service will be restarted.
# The health_check_cmd parameter must be set to true to use this functionality.
Expand Down Expand Up @@ -121,6 +125,7 @@
Optional[Boolean] $read_only = false,
Optional[String] $health_check_cmd = undef,
Optional[Boolean] $restart_on_unhealthy = false,
Optional[Integer] $health_check_interval = undef,
) {
include docker::params
if ($socket_connect != []) {
Expand Down Expand Up @@ -193,6 +198,7 @@
read_only => $read_only,
health_check_cmd => $health_check_cmd,
restart_on_unhealthy => $restart_on_unhealthy,
health_check_interval => $health_check_interval,
})

$sanitised_title = regsubst($title, '[^0-9A-Za-z.\-_]', '-', 'G')
Expand Down Expand Up @@ -449,17 +455,17 @@
path => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'],
command => 'systemctl daemon-reload',
refreshonly => true,
require => File[$initscript],
subscribe => File[$initscript],
require => [File[$initscript],File[$runscript]],
subscribe => [File[$initscript],File[$runscript]]
}
Exec["docker-${sanitised_title}-systemd-reload"] -> Service<| title == "${service_prefix}${sanitised_title}" |>
}

if $restart_service {
File[$initscript] ~> Service<| title == "${service_prefix}${sanitised_title}" |>
[File[$initscript],File[$runscript]] ~> Service<| title == "${service_prefix}${sanitised_title}" |>
}
else {
File[$initscript] -> Service<| title == "${service_prefix}${sanitised_title}" |>
[File[$initscript],File[$runscript]] -> Service<| title == "${service_prefix}${sanitised_title}" |>
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": [
{"name":"puppetlabs/stdlib","version_requirement":">= 4.24.0"},
{"name":"puppetlabs/apt","version_requirement":">= 4.4.1"},
{"name":"puppetlabs/translate","version_requirement":">= 0.0.1 < 1.1.0"},
{"name":"puppetlabs/translate","version_requirement":">= 0.0.1 <=1.1.0"},
{"name":"puppetlabs/powershell","version_requirement":">= 2.1.4"},
{"name":"puppetlabs/reboot","version_requirement":">= 2.0.0"}
],
Expand Down
3 changes: 2 additions & 1 deletion spec/defines/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
'command' => 'command',
'image' => 'base',
'health_check_cmd' => 'pwd',
'restart_on_unhealthy' => true
'restart_on_unhealthy' => true,
'health_check_interval' => 60,
}}
if (systemd)
it { should contain_file(initscript).with_content(/ExecStop=-\/usr\/bin\/docker stop --time=0 /) }
Expand Down

0 comments on commit 12fdd37

Please sign in to comment.