X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/c6294e91397c6feebd9b9f0e33da615b3ca17998..fe856c739aa6043338720888b84d476b88bfd193:/cookbooks/podman/resources/service.rb diff --git a/cookbooks/podman/resources/service.rb b/cookbooks/podman/resources/service.rb index 6052b7fb2..5ef0b5885 100644 --- a/cookbooks/podman/resources/service.rb +++ b/cookbooks/podman/resources/service.rb @@ -24,7 +24,9 @@ default_action :create property :service, String, :name_property => true property :description, String, :required => true property :image, String, :required => true -property :ports, Hash +property :ports, Hash, :default => {} +property :environment, Hash, :default => {} +property :volume, Hash, :default => {} action :create do systemd_service new_resource.service do @@ -33,7 +35,7 @@ action :create do notify_access "all" environment "PODMAN_SYSTEMD_UNIT" => "%n" exec_start_pre "/bin/rm --force %t/%n.ctr-id" - exec_start "/usr/bin/podman run --cidfile=%t/%n.ctr-id --cgroups=no-conmon --userns=auto --label=io.containers.autoupdate=registry --network=slirp4netns:mtu=1500 #{publish_options} --rm --sdnotify=conmon --detach --replace --name=%N #{new_resource.image}" + exec_start "/usr/bin/podman run --cidfile=%t/%n.ctr-id --cgroups=no-conmon --userns=auto --label=io.containers.autoupdate=registry --pids-limit=-1 #{publish_options} #{environment_options} #{volume_options} --rm --sdnotify=conmon --detach --replace --name=%N #{new_resource.image}" exec_stop "/usr/bin/podman stop --ignore --time=10 --cidfile=%t/%n.ctr-id" exec_stop_post "/usr/bin/podman rm --force --ignore --cidfile=%t/%n.ctr-id" timeout_start_sec 180 @@ -42,9 +44,12 @@ action :create do end # No action :start here to avoid a start and then immediate :restart, due to subscribe, on first run + # FIXME: Ubuntu 22.04 podman/crun bug workaround "retries" service new_resource.service do action :enable subscribes :restart, "systemd_service[#{new_resource.service}]", :immediately + retries 4 # Workaround https://github.com/containers/podman/issues/9752 + retry_delay 5 end # Ensure the service is started if not running, replies on status of service resource @@ -70,4 +75,16 @@ action_class do "--publish=127.0.0.1:#{host}:#{guest}" end.join(" ") end + + def environment_options + new_resource.environment.collect do |key, value| + "-e '#{key}=#{value}'" + end.join(" ") + end + + def volume_options + new_resource.volume.collect do |key, value| + "-v '#{key}:#{value}'" + end.join(" ") + end end