diff --git a/manifests/run.pp b/manifests/run.pp index 74ddbae17..8b7d49078 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 $service_provider == 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.') } } diff --git a/spec/defines/run_spec.rb b/spec/defines/run_spec.rb index d6c53c5f5..bb5d4eded 100755 --- a/spec/defines/run_spec.rb +++ b/spec/defines/run_spec.rb @@ -145,6 +145,13 @@ end end + context 'when passing `service_provider`' do + context 'when forcing use of systemd' do + let(:params) { {'command' => 'command', 'image' => 'base', 'service_provider' => 'systemd'} } + it { should contain_file('/etc/systemd/system/docker-sample.service') } + end + end + context 'removing containers and volumes' do context 'when trying to remove the volume and not the container on stop' do let(:params) {{