Skip to content

Commit

Permalink
Fix for "Container fails to restart when resource notified southalc#9"…
Browse files Browse the repository at this point in the history
… reported by toreanderson
  • Loading branch information
southalc committed Feb 12, 2021
1 parent f46edcd commit 89c428b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
43 changes: 22 additions & 21 deletions manifests/container.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -159,6 +159,7 @@
fi
|END
notify => Exec["podman_remove_container_${handle}"],
require => $requires,
* => $exec_defaults,
}

Expand All @@ -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,
}
Expand All @@ -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,
}
Expand All @@ -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,
}
Expand All @@ -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}"]
Expand Down Expand Up @@ -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'],
}
}
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 89c428b

Please sign in to comment.