From 220b6a5c68e903e3054ac3cd38f4daf3aa35ee9c Mon Sep 17 00:00:00 2001 From: Mark Wilson Date: Mon, 27 Nov 2017 17:14:35 +0000 Subject: [PATCH] (CLOUD-1560)-adding-functionality to remove systemd service files. --- README.md | 8 ++++++++ manifests/run.pp | 4 ++++ spec/acceptance/docker_full_spec.rb | 1 + spec/defines/run_spec.rb | 1 + 4 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 00b3a6e2..e3b8ca3b 100755 --- a/README.md +++ b/README.md @@ -356,6 +356,14 @@ If using Hiera, you can configure the `docker::run_instance` class: command: '/bin/sh -c "while true; do echo hello world; sleep 1; done"' ``` +To remove a running container, add the following code to the manifest file. This will also remove the systemd service file associated with the container. + +'''puppet +docker::run { 'helloworld': + ensure => absent, +} +''' + ### Networks Docker 1.9.x officially supports networks. To expose the `docker_network` type, which is used to manage networks, add the following code to the manifest file: diff --git a/manifests/run.pp b/manifests/run.pp index fac202a7..93542ed6 100755 --- a/manifests/run.pp +++ b/manifests/run.pp @@ -320,6 +320,10 @@ timeout => 0 } + File { "/etc/systemd/system/${service_prefix}${sanitised_title}.service": + ensure => absent, + path => "/etc/systemd/system/${service_prefix}${sanitised_title}.service", + } } else { file { $initscript: diff --git a/spec/acceptance/docker_full_spec.rb b/spec/acceptance/docker_full_spec.rb index 5ec64432..478df570 100644 --- a/spec/acceptance/docker_full_spec.rb +++ b/spec/acceptance/docker_full_spec.rb @@ -89,6 +89,7 @@ class { 'docker':} sleep 15 shell('docker inspect container-3-6', :acceptable_exit_codes => [1]) + shell('test -f /etc/systemd/system/container-3-6.service', :acceptable_exit_codes => [1]) end end diff --git a/spec/defines/run_spec.rb b/spec/defines/run_spec.rb index a041990d..80fabd22 100755 --- a/spec/defines/run_spec.rb +++ b/spec/defines/run_spec.rb @@ -658,6 +658,7 @@ it { should compile.with_all_deps } it { should contain_service('docker-sample').with_ensure(false) } it { should contain_exec("remove container docker-sample").with_command('docker rm -v sample') } + it { should_not contain_file('docker-sample.service')} end end