From 89c428b2518fdc97bda0638a5432194f747f41b6 Mon Sep 17 00:00:00 2001 From: Chris Southall Date: Thu, 11 Feb 2021 20:50:03 -0600 Subject: [PATCH] Fix for "Container fails to restart when resource notified #9" reported by toreanderson --- CHANGELOG.md | 4 ++++ manifests/container.pp | 43 +++++++++++++++++++++--------------------- metadata.json | 2 +- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c36811..ce261f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Release 0.2.4 + +- Fix "Container fails to restart when resource notified" reported by toreanderson + ## Release 0.2.3 - Fix for flags that don't require values - Contributed by jtopper diff --git a/manifests/container.pp b/manifests/container.pp index b66d224..1ac5132 100644 --- a/manifests/container.pp +++ b/manifests/container.pp @@ -103,11 +103,11 @@ ], cwd => User[$user]['home'], user => $user, - require => [ - Podman::Rootless[$user], - Service['systemd-logind'], - ], } + $requires = [ + Podman::Rootless[$user], + Service['systemd-logind'], + ] $service_unit_file ="${User[$user]['home']}/.config/systemd/user/podman-${container_name}.service" # Reload systemd when service files are updated @@ -159,6 +159,7 @@ fi |END notify => Exec["podman_remove_container_${handle}"], + require => $requires, * => $exec_defaults, } @@ -182,37 +183,32 @@ test "\${running_digest}" = "\${latest_digest}" fi |END - notify => Exec["podman_remove_container_and_image_${handle}"], + notify => [ + Exec["podman_remove_image_${handle}"], + Exec["podman_remove_container_${handle}"], + ], + require => $requires, * => $exec_defaults, } } - Exec { "podman_remove_container_and_image_${handle}": + Exec { "podman_remove_image_${handle}": # Try nicely to stop the container, but then insist provider => 'shell', - command => @("END"/$L), - image=\$(podman container inspect ${container_name} --format '{{.ImageName}}') - ${systemctl} stop podman-${container_name} || podman container stop ${container_name} - podman container rm --force ${container_name} - status=$? - podman rmi --force \${image} - exit \${status} - |END + command => "podman rmi --force ${image}", refreshonly => true, notify => Exec["podman_create_${handle}"], + require => [ $requires, Exec["podman_remove_container_${handle}"]], * => $exec_defaults, } Exec { "podman_remove_container_${handle}": # Try nicely to stop the container, but then insist provider => 'shell', - command => @("END"/$L), - image=\$(podman container inspect ${container_name} --format '{{.ImageName}}') - ${systemctl} stop podman-${container_name} || podman container stop ${container_name} - podman container rm --force ${container_name} - |END + command => "${systemctl} stop podman-${container_name} || podman container stop ${container_name}", refreshonly => true, notify => Exec["podman_create_${handle}"], + require => $requires, * => $exec_defaults, } @@ -239,6 +235,7 @@ command => "podman container create ${_flags} ${image} ${command}", unless => "podman container exists ${container_name}", notify => Exec["podman_generate_service_${handle}"], + require => $requires, * => $exec_defaults, } @@ -247,6 +244,7 @@ command => "podman generate systemd ${_service_flags} ${container_name} > ${service_unit_file}", refreshonly => true, notify => Exec["service_podman_${handle}"], + require => $requires, * => $exec_defaults, } @@ -263,6 +261,7 @@ ${systemctl} is-active podman-${container_name}.service && \ ${systemctl} is-enabled podman-${container_name}.service |END + require => $requires, * => $exec_defaults, } Exec["podman_systemd_${user}_reload"] -> Exec["service_podman_${handle}"] @@ -295,12 +294,14 @@ podman container rm --force ${container_name} |END unless => "podman container exists ${container_name}; test $? -eq 1", + require => $requires, * => $exec_defaults, } File { $service_unit_file: - ensure => absent, - notify => Exec['podman_systemd_reload'], + ensure => absent, + require => $requires, + notify => Exec['podman_systemd_reload'], } } diff --git a/metadata.json b/metadata.json index 4b7ed11..3c27003 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "southalc-podman", - "version": "0.2.3", + "version": "0.2.4", "author": "Chris Southall", "summary": "Manage podman containers with puppet", "license": "Apache-2.0",