]> git.openstreetmap.org Git - chef.git/blob - cookbooks/systemd/resources/path.rb
0bff3ecffec6dfb7538828dcb516a98873efacc9
[chef.git] / cookbooks / systemd / resources / path.rb
1 #
2 # Cookbook Name:: systemd
3 # Resource:: systemd_path
4 #
5 # Copyright 2017, 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 # http://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 default_action :create
21
22 property :path, String, :name_property => true
23 property :description, String, :required => true
24 property :after, [String, Array]
25 property :wants, [String, Array]
26 property :path_exists, [String, Array]
27 property :path_exists_glob, [String, Array]
28 property :path_changed, [String, Array]
29 property :path_modified, [String, Array]
30 property :directory_not_empty, [String, Array]
31 property :unit, String
32 property :make_directory, [TrueClass, FalseClass]
33 property :directory_mode, Integer
34
35 action :create do
36   path_variables = new_resource.to_hash
37
38   template "/etc/systemd/system/#{new_resource.path}.path" do
39     cookbook "systemd"
40     source "path.erb"
41     owner "root"
42     group "root"
43     mode 0o644
44     variables path_variables
45   end
46
47   execute "systemctl-reload-#{new_resource.path}.path" do
48     action :nothing
49     command "systemctl daemon-reload"
50     user "root"
51     group "root"
52     subscribes :run, "template[/etc/systemd/system/#{new_resource.path}.path]"
53   end
54 end
55
56 action :delete do
57   file "/etc/systemd/system/#{new_resource.path}.path" do
58     action :delete
59   end
60
61   execute "systemctl-reload-#{new_resource.path}.path" do
62     action :nothing
63     command "systemctl daemon-reload"
64     user "root"
65     group "root"
66     subscribes :run, "file[/etc/systemd/system/#{new_resource.path}.path]"
67   end
68 end