]> git.openstreetmap.org Git - chef.git/blob - cookbooks/systemd/resources/socket.rb
Merge remote-tracking branch 'tigerfell/pr257'
[chef.git] / cookbooks / systemd / resources / socket.rb
1 #
2 # Cookbook:: systemd
3 # Resource:: systemd_socket
4 #
5 # Copyright:: 2021, 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 :socket, String, :name_property => true
25 property :description, String, :required => [:create]
26 property :after, [String, Array]
27 property :wants, [String, Array]
28 property :listen_stream, [String, Array]
29 property :listen_datagram, [String, Array]
30 property :listen_sequential_packet, [String, Array]
31 property :listen_fifo, [String, Array]
32 property :listen_special, [String, Array]
33 property :listen_netlink, [String, Array]
34 property :listen_message_queue, [String, Array]
35 property :listen_usb_function, [String, Array]
36 property :socket_protocol, String
37 property :bind_ipv6_only, String
38 property :backlog, Integer
39 property :bind_to_device, String
40 property :socket_user, String
41 property :socket_group, String
42 property :socket_mode, Integer
43 property :directory_mode, Integer
44 property :accept, [true, false]
45 property :writable, [true, false]
46 property :max_connections, Integer
47 property :max_connections_per_source, Integer
48 property :keep_alive, [true, false]
49 property :keep_alive_time_sec, Integer
50 property :keep_alive_interval_sec, Integer
51 property :keep_alive_probes, Integer
52 property :no_delay, [true, false]
53 property :priority, Integer
54 property :defer_accept_sec, Integer
55 property :receive_buffer, Integer
56 property :send_buffer, Integer
57 property :ip_tos, Integer
58 property :ip_ttl, Integer
59 property :mark, Integer
60 property :reuse_port, [true, false]
61 property :pipe_size, Integer
62 property :message_queue_max_messages, Integer
63 property :message_queue_message_size, Integer
64 property :free_bind, [true, false]
65 property :transparent, [true, false]
66 property :broadcast, [true, false]
67 property :pass_credentials, [true, false]
68 property :pass_security, [true, false]
69 property :tcp_congestion, String
70 property :exec_start_pre, [String, Array]
71 property :exec_start, [String, Array]
72 property :exec_start_post, [String, Array]
73 property :exec_stop, [String, Array]
74 property :timeout_sec, [Integer, String]
75 property :service, String
76 property :remove_on_stop, [true, false]
77 property :symlinks, [String, Array]
78 property :file_descriptor_name, String
79 property :trigger_limit_interval_sec, [Integer, String]
80 property :trigger_limit_burst, Integer
81
82 action :create do
83   socket_variables = new_resource.to_hash
84
85   template "/etc/systemd/system/#{new_resource.socket}.socket" do
86     cookbook "systemd"
87     source "socket.erb"
88     owner "root"
89     group "root"
90     mode "644"
91     variables socket_variables
92   end
93
94   execute "systemctl-reload-#{new_resource.socket}.socket" do
95     action :nothing
96     command "systemctl daemon-reload"
97     user "root"
98     group "root"
99     subscribes :run, "template[/etc/systemd/system/#{new_resource.socket}.socket]"
100   end
101 end
102
103 action :delete do
104   file "/etc/systemd/system/#{new_resource.socket}.socket" do
105     action :delete
106   end
107
108   execute "systemctl-reload-#{new_resource.socket}.socket" do
109     action :nothing
110     command "systemctl daemon-reload"
111     user "root"
112     group "root"
113     subscribes :run, "file[/etc/systemd/system/#{new_resource.socket}.socket]"
114   end
115 end