Skip to content

Commit a1d090a

Browse files
authored
Merge pull request #279 from MWilsonPuppet/CLOUD-2018-Add-health-check-interval
CLOUD-2018-Add-health-check-interval
2 parents 7e7209f + 995588b commit a1d090a

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,15 @@ docker::run { 'helloworld':
386386
}
387387
```
388388

389-
To enable the restart of an unhealthy container add the following code to the manifest file.
389+
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.
390390

391391
```puppet
392392
docker::run { 'helloworld':
393393
image => 'base',
394394
command => 'command',
395-
health_check_command => '<command_to_execute_to_check_your_containers_health>',
395+
health_check_cmd => '<command_to_execute_to_check_your_containers_health>',
396396
restart_on_unhealthy => true,
397+
health_check_interval => '<time between running docker healthcheck>',
397398
```
398399

399400
To run command on Windows 2016 requires the `restart` parameter to be set:

lib/puppet/parser/functions/docker_run_flags.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ module Puppet::Parser::Functions
5050
flags << "--health-cmd='#{opts['health_check_cmd']}'"
5151
end
5252

53+
if opts['health_check_interval'].to_s != 'undef'
54+
flags << "--health-interval=#{opts['health_check_interval']}s"
55+
end
56+
5357
if opts['tty']
5458
flags << '-t'
5559
end

manifests/run.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
# (optional) Specifies the command to execute to check that the container is healthy using the docker health check functionality.
5353
# Default: undef
5454
#
55+
# [*health_check_interval*]
56+
# (optional) Specifies the interval that the health check command will execute in seconds.
57+
# Default: undef
58+
#
5559
# [*restart_on_unhealthy*]
5660
# (optional) Checks the health status of Docker container and if it is unhealthy the service will be restarted.
5761
# The health_check_cmd parameter must be set to true to use this functionality.
@@ -121,6 +125,7 @@
121125
Optional[Boolean] $read_only = false,
122126
Optional[String] $health_check_cmd = undef,
123127
Optional[Boolean] $restart_on_unhealthy = false,
128+
Optional[Integer] $health_check_interval = undef,
124129
) {
125130
include docker::params
126131
if ($socket_connect != []) {
@@ -193,6 +198,7 @@
193198
read_only => $read_only,
194199
health_check_cmd => $health_check_cmd,
195200
restart_on_unhealthy => $restart_on_unhealthy,
201+
health_check_interval => $health_check_interval,
196202
})
197203

198204
$sanitised_title = regsubst($title, '[^0-9A-Za-z.\-_]', '-', 'G')

spec/defines/run_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@
132132
'command' => 'command',
133133
'image' => 'base',
134134
'health_check_cmd' => 'pwd',
135-
'restart_on_unhealthy' => true
135+
'restart_on_unhealthy' => true,
136+
'health_check_interval' => 60,
136137
}}
137138
if (systemd)
138139
it { should contain_file(initscript).with_content(/ExecStop=-\/usr\/bin\/docker stop --time=0 /) }

0 commit comments

Comments
 (0)