Skip to content

Commit d860415

Browse files
committed
Fix container running check to work for windows hosts
1 parent 043395e commit d860415

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Diff for: manifests/run.pp

+5-2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@
240240
$cidfile = "${::docker_user_temp_path}/${service_prefix}${sanitised_title}.cid"
241241
# lint:ignore:140chars
242242
$restart_check = "${docker_command} inspect ${sanitised_title} -f '{{ if eq \\\"unhealthy\\\" .State.Health.Status }} {{ .Name }}{{ end }}' | findstr ${sanitised_title}"
243+
$container_running_check = "\$state = ${docker_command} inspect ${sanitised_title} -f \"{{ .State.Running }}\"; if (\$state -ieq \"true\") { Exit 0 } else { Exit 1 }"
244+
243245
# lint:endignore
244246
} else {
245247
$exec_environment = 'HOME=/root'
@@ -249,6 +251,7 @@
249251
$cidfile = "/var/run/${service_prefix}${sanitised_title}.cid"
250252
# lint:ignore:140chars
251253
$restart_check = "${docker_command} inspect ${sanitised_title} -f '{{ if eq \"unhealthy\" .State.Health.Status }} {{ .Name }}{{ end }}' | grep ${sanitised_title}"
254+
$container_running_check = "${docker_command} inspect ${sanitised_title} -f \"{{ .State.Running }}\" | grep true"
252255
# lint:endignore
253256
}
254257

@@ -311,7 +314,7 @@
311314
if $running == false {
312315
exec { "stop ${title} with docker":
313316
command => "${docker_command} stop --time=${stop_wait_time} ${sanitised_title}",
314-
unless => "${docker_command} inspect ${sanitised_title} -f \"{{ .State.Running }}\" | grep true",
317+
onlyif => $container_running_check,
315318
environment => $exec_environment,
316319
path => $exec_path,
317320
provider => $exec_provider,
@@ -320,7 +323,7 @@
320323
} else {
321324
exec { "start ${title} with docker":
322325
command => "${docker_command} start ${sanitised_title}",
323-
onlyif => "${docker_command} inspect ${sanitised_title} -f \"{{ .State.Running }}\" | grep false",
326+
unless => $container_running_check,
324327
environment => $exec_environment,
325328
path => $exec_path,
326329
provider => $exec_provider,

Diff for: spec/defines/run_windows_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
it { should contain_exec('run sample with docker').with_command(/--restart="always"/) }
4141
it { should contain_exec('run sample with docker').with_command(/base command/) }
4242
it { should contain_exec('run sample with docker').with_timeout(3000) }
43+
it { should contain_exec('start sample with docker').with_command(/docker start sample/) }
4344
end
4445

4546
context 'with restart policy set to on-failure' do
@@ -82,6 +83,12 @@
8283
it { should_not contain_file('C:/Users/Administrator/AppData/Local/Temp/docker-sample.cid"')}
8384
end
8485

86+
context 'with ensure present and running false' do
87+
let(:params) { {'ensure' => 'present', 'image' => 'base', 'restart' => 'always', 'running' => false} }
88+
it { should compile.with_all_deps }
89+
it { should contain_exec("stop sample with docker").with_command('docker stop --time=0 sample') }
90+
end
91+
8592
context 'with ensure present and no restart policy' do
8693
let(:params) { {'ensure' => 'present', 'image' => 'base'} }
8794
it do

0 commit comments

Comments
 (0)