|
76 | 76 | # (optional) Specify an additional unless for the Docker run command when using restart.
|
77 | 77 | # Default: undef
|
78 | 78 | #
|
| 79 | +# [*after_create*] |
| 80 | +# (optional) Specifies the command to execute after container is created but before it is started. |
| 81 | +# Default: undef |
| 82 | +# |
79 | 83 | define docker::run(
|
80 | 84 | Optional[Pattern[/^[\S]*$/]] $image,
|
81 | 85 | Optional[Pattern[/^present$|^absent$/]] $ensure = 'present',
|
|
105 | 109 | Variant[String,Boolean] $docker_service = false,
|
106 | 110 | Optional[Boolean] $disable_network = false,
|
107 | 111 | Optional[Boolean] $privileged = false,
|
108 |
| - Optional[Boolean] $detach = undef, |
109 | 112 | Variant[String,Array[String],Undef] $extra_parameters = undef,
|
110 | 113 | Optional[String] $systemd_restart = 'on-failure',
|
111 | 114 | Variant[String,Hash,Undef] $extra_systemd_parameters = {},
|
|
120 | 123 | Optional[String] $restart = undef,
|
121 | 124 | Variant[String,Boolean] $before_start = false,
|
122 | 125 | Variant[String,Boolean] $before_stop = false,
|
| 126 | + Optional[String] $after_create = undef, |
123 | 127 | Optional[Boolean] $remove_container_on_start = true,
|
124 | 128 | Optional[Boolean] $remove_container_on_stop = true,
|
125 | 129 | Optional[Boolean] $remove_volume_on_start = false,
|
|
165 | 169 | assert_type(Pattern[/^(no|always|on-success|on-failure|on-abnormal|on-abort|on-watchdog)$/], $systemd_restart)
|
166 | 170 | }
|
167 | 171 |
|
168 |
| - if $detach == undef { |
169 |
| - $valid_detach = $docker::params::detach_service_in_init |
170 |
| - } else { |
171 |
| - $valid_detach = $detach |
172 |
| - } |
173 |
| - |
174 | 172 | $extra_parameters_array = any2array($extra_parameters)
|
175 | 173 | $after_array = any2array($after)
|
176 | 174 | $depends_array = any2array($depends)
|
177 | 175 | $depend_services_array = any2array($depend_services)
|
178 | 176 |
|
179 | 177 | $docker_run_flags = docker_run_flags({
|
180 | 178 | cpuset => any2array($cpuset),
|
181 |
| - detach => $valid_detach, |
182 | 179 | disable_network => $disable_network,
|
183 | 180 | dns => any2array($dns),
|
184 | 181 | dns_search => any2array($dns_search),
|
|
320 | 317 | }
|
321 | 318 | } else {
|
322 | 319 |
|
| 320 | + $docker_run_inline_start = template('docker/docker-run-start.erb') |
| 321 | + $docker_run_inline_stop = template('docker/docker-run-stop.erb') |
| 322 | + |
323 | 323 | case $docker::params::service_provider {
|
324 | 324 | 'systemd': {
|
325 | 325 | $initscript = "/etc/systemd/system/${service_prefix}${sanitised_title}.service"
|
326 |
| - $runscript = "/usr/local/bin/docker-run-${sanitised_title}.sh" |
327 |
| - $run_template = 'docker/usr/local/bin/docker-run.sh.erb' |
| 326 | + $startscript = "/usr/local/bin/docker-run-${sanitised_title}-start.sh" |
| 327 | + $stopscript = "/usr/local/bin/docker-run-${sanitised_title}-stop.sh" |
| 328 | + $startstop_template = 'docker/usr/local/bin/docker-run.sh.epp' |
328 | 329 | $init_template = 'docker/etc/systemd/system/docker-run.erb'
|
329 | 330 | $mode = '0640'
|
330 | 331 | }
|
331 | 332 | 'upstart': {
|
332 | 333 | $initscript = "/etc/init.d/${service_prefix}${sanitised_title}"
|
333 | 334 | $init_template = 'docker/etc/init.d/docker-run.erb'
|
334 | 335 | $mode = '0750'
|
335 |
| - $runscript = undef |
336 |
| - $run_template = undef |
| 336 | + $startscript = undef |
| 337 | + $stopscript = undef |
| 338 | + $starstop_template = undef |
337 | 339 | }
|
338 | 340 | default: {
|
339 | 341 | if $::osfamily != 'windows' {
|
|
386 | 388 | ensure => absent,
|
387 | 389 | path => "/etc/systemd/system/${service_prefix}${sanitised_title}.service",
|
388 | 390 | }
|
| 391 | + if ($startscript) { |
| 392 | + file { $startscript: |
| 393 | + ensure => absent |
| 394 | + } |
| 395 | + } |
| 396 | + if ($stopscript) { |
| 397 | + file { $stopscript: |
| 398 | + ensure => absent |
| 399 | + } |
| 400 | + } |
389 | 401 | }
|
390 | 402 | else {
|
391 | 403 | file { $cidfile:
|
|
394 | 406 | }
|
395 | 407 | }
|
396 | 408 | else {
|
397 |
| - if ($runscript) { |
398 |
| - file { $runscript: |
| 409 | + if ($startscript) { |
| 410 | + file { $startscript: |
| 411 | + ensure => present, |
| 412 | + content => epp($startstop_template, {'script' => $docker_run_inline_start}), |
| 413 | + owner => 'root', |
| 414 | + group => $docker_group, |
| 415 | + mode => '0770' |
| 416 | + } |
| 417 | + } |
| 418 | + if ($stopscript) { |
| 419 | + file { $stopscript: |
399 | 420 | ensure => present,
|
400 |
| - content => template($run_template), |
| 421 | + content => epp($startstop_template, {'script' => $docker_run_inline_stop}), |
401 | 422 | owner => 'root',
|
402 | 423 | group => $docker_group,
|
403 | 424 | mode => '0770'
|
|
471 | 492 | path => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'],
|
472 | 493 | command => 'systemctl daemon-reload',
|
473 | 494 | refreshonly => true,
|
474 |
| - require => [File[$initscript],File[$runscript]], |
475 |
| - subscribe => [File[$initscript],File[$runscript]] |
| 495 | + require => [File[$initscript],File[$startscript],File[$stopscript]], |
| 496 | + subscribe => [File[$initscript],File[$startscript],File[$stopscript]] |
476 | 497 | }
|
477 | 498 | Exec["docker-${sanitised_title}-systemd-reload"] -> Service<| title == "${service_prefix}${sanitised_title}" |>
|
478 | 499 | }
|
479 | 500 |
|
480 | 501 | if $restart_service {
|
481 |
| - if $runscript { |
482 |
| - [File[$initscript],File[$runscript]] ~> Service<| title == "${service_prefix}${sanitised_title}" |> |
| 502 | + if $startscript or $stopscript { |
| 503 | + [File[$initscript],File[$startscript],File[$stopscript]] ~> Service<| title == "${service_prefix}${sanitised_title}" |> |
483 | 504 | }
|
484 | 505 | else {
|
485 | 506 | [File[$initscript]] ~> Service<| title == "${service_prefix}${sanitised_title}" |>
|
486 | 507 | }
|
487 | 508 | }
|
488 | 509 | else {
|
489 |
| - if $runscript { |
490 |
| - [File[$initscript],File[$runscript]] -> Service<| title == "${service_prefix}${sanitised_title}" |> |
| 510 | + if $startscript or $stopscript { |
| 511 | + [File[$initscript],File[$startscript],File[$stopscript]] -> Service<| title == "${service_prefix}${sanitised_title}" |> |
491 | 512 | }
|
492 | 513 | else {
|
493 | 514 | [File[$initscript]] -> Service<| title == "${service_prefix}${sanitised_title}" |>
|
|
0 commit comments