]> git.openstreetmap.org Git - chef.git/blob - cookbooks/systemd/resources/container.rb
Use volume for nested podman container storage
[chef.git] / cookbooks / systemd / resources / container.rb
1 #
2 # Cookbook:: systemd
3 # Resource:: systemd_container
4 #
5 # Copyright:: 2026, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # https://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 unified_mode true
21
22 default_action :create
23
24 property :container, String, :name_property => true
25 property :description, String
26 property :image, String
27 property :command, String
28 property :ports, Hash, :default => {}
29 property :environment, Hash, :default => {}
30 property :volumes, Hash, :default => {}
31 property :pids_limit, Integer
32 property :timeout_start_sec, Integer
33 property :restart, String,
34          :is => %w[on-success on-failure on-abnormal on-watchdog on-abort always]
35
36 action :create do
37   container_variables = new_resource.to_hash
38
39   template config_name do
40     cookbook "systemd"
41     source "container.erb"
42     owner "root"
43     group "root"
44     mode "644"
45     variables container_variables
46   end
47
48   execute "systemctl-reload" do
49     action :nothing
50     command "systemctl daemon-reload"
51     user "root"
52     group "root"
53     subscribes :run, "template[#{config_name}]"
54   end
55 end
56
57 action :delete do
58   file config_name do
59     action :delete
60   end
61
62   execute "systemctl-reload" do
63     action :nothing
64     command "systemctl daemon-reload"
65     user "root"
66     group "root"
67     subscribes :run, "file[#{config_name}]"
68   end
69 end
70
71 action_class do
72   def config_name
73     "/etc/containers/systemd/#{new_resource.container}.container"
74   end
75 end