Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding service_provider on docker::run #756

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 30 additions & 38 deletions manifests/run.pp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
$dns = [],
$dns_search = [],
$lxc_conf = [],
$service_provider = undef,
$service_prefix = 'docker-',
$restart_service = true,
$restart_service_on_docker_refresh = true,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.')
}
}

Expand Down
7 changes: 7 additions & 0 deletions spec/defines/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) {{
Expand Down