]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/podman/resources/service.rb
podman: increase default pid limit.
[chef.git] / cookbooks / podman / resources / service.rb
index 3f3e8054cb82b81a7dbef0738bd4c6253660226f..07c98c1a22a1c137c342054fa2a9d74b52f2408e 100644 (file)
@@ -25,6 +25,7 @@ property :service, String, :name_property => true
 property :description, String, :required => true
 property :image, String, :required => true
 property :ports, Hash
+property :environment, Hash, :default => {}
 
 action :create do
   systemd_service new_resource.service do
@@ -33,16 +34,27 @@ 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 #{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 --network=slirp4netns:mtu=1500 --pid-limit=-1 #{publish_options} #{environment_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
     timeout_stop_sec 70
     restart "on-failure"
   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, :start]
-    subscribes :restart, "systemd_service[#{new_resource.service}]"
+    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
+  notify_group new_resource.service do
+    action :run
+    notifies :start, "service[#{new_resource.service}]", :immediately
   end
 end
 
@@ -62,4 +74,10 @@ 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
 end