From 220b28c784e5753b0ad4a419d99d40f847dbd96e Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sun, 1 Jul 2018 23:59:15 +0100 Subject: [PATCH] Allow overriding service_provider on docker::run Its possible to override the `service_provider` when managing the docker daemon in case the defaults in params.pp aren't correct, but not when defining a container using `docker::run`. This change adds a new `service_provider` parameter to the run defined type, so that containers can also be managed in these situations. Fixes garethr/garethr-docker#755 --- manifests/run.pp | 68 +++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 38 deletions(-) diff --git a/manifests/run.pp b/manifests/run.pp index 74ddbae17..75cdf2bbb 100755 --- a/manifests/run.pp +++ b/manifests/run.pp @@ -81,6 +81,7 @@ $dns = [], $dns_search = [], $lxc_conf = [], + $service_provider = undef, $service_prefix = 'docker-', $restart_service = true, $restart_service_on_docker_refresh = true, @@ -140,6 +141,13 @@ if $hostname { validate_string($hostname) } + if $detach == undef { + $valid_service_provider = $docker::params::service_provider + } else { + validate_string($service_provider) + $valid_service_provider = $service_provider + } + validate_bool($running) validate_bool($disable_network) validate_bool($privileged) @@ -245,54 +253,38 @@ } } else { - case $::osfamily { - 'Debian': { - $deprecated_initscript = "/etc/init/${service_prefix}${sanitised_title}.conf" - $hasstatus = true - if ($::operatingsystem == 'Debian' and versioncmp($::operatingsystemmajrelease, '8') >= 0) or - ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '15.04') >= 0) { - $initscript = "/etc/systemd/system/${service_prefix}${sanitised_title}.service" - $init_template = 'docker/etc/systemd/system/docker-run.erb' - $uses_systemd = true - $mode = '0640' - } else { - $uses_systemd = false + if $valid_service_provider == 'systemd' { + $initscript = "/etc/systemd/system/${service_prefix}${sanitised_title}.service" + $init_template = 'docker/etc/systemd/system/docker-run.erb' + $hasstatus = true + $mode = '0640' + $uses_systemd = true + } else { + $uses_systemd = false + + case $::osfamily { + 'Debian': { + $deprecated_initscript = "/etc/init/${service_prefix}${sanitised_title}.conf" $initscript = "/etc/init.d/${service_prefix}${sanitised_title}" $init_template = 'docker/etc/init.d/docker-run.erb' + $hasstatus = true $mode = '0750' } - } - 'RedHat': { - if ($::operatingsystem == 'Amazon') or (versioncmp($::operatingsystemrelease, '7.0') < 0) { + 'RedHat': { $initscript = "/etc/init.d/${service_prefix}${sanitised_title}" $init_template = 'docker/etc/init.d/docker-run.erb' $hasstatus = undef $mode = '0750' - $uses_systemd = false - } else { - $initscript = "/etc/systemd/system/${service_prefix}${sanitised_title}.service" - $init_template = 'docker/etc/systemd/system/docker-run.erb' + } + 'Gentoo': { + $initscript = "/etc/init.d/${service_prefix}${sanitised_title}" + $init_template = 'docker/etc/init.d/docker-run.gentoo.erb' $hasstatus = true - $mode = '0640' - $uses_systemd = true + $mode = '0770' + } + default: { + fail('Docker needs a Debian, RedHat, Gentoo or other systemd-based system.') } - } - 'Archlinux': { - $initscript = "/etc/systemd/system/${service_prefix}${sanitised_title}.service" - $init_template = 'docker/etc/systemd/system/docker-run.erb' - $hasstatus = true - $mode = '0640' - $uses_systemd = true - } - 'Gentoo': { - $initscript = "/etc/init.d/${service_prefix}${sanitised_title}" - $init_template = 'docker/etc/init.d/docker-run.gentoo.erb' - $hasstatus = true - $mode = '0770' - $uses_systemd = false - } - default: { - fail('Docker needs a Debian, RedHat, Archlinux or Gentoo based system.') } }