]> git.openstreetmap.org Git - chef.git/blob - cookbooks/systemd/resources/service.rb
Fix collection of PSU details from dmidecode
[chef.git] / cookbooks / systemd / resources / service.rb
1 #
2 # Cookbook Name:: systemd
3 # Resource:: systemd_service
4 #
5 # Copyright 2016, 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 :name, String
23 property :description, String, :required => true
24 property :after, [String, Array]
25 property :type, String,
26          :default => "simple",
27          :is => %w(simple forking oneshot dbus notify idle)
28 property :limit_nofile, Fixnum
29 property :environment, Hash, :default => {}
30 property :environment_file, String
31 property :exec_start_pre, String
32 property :exec_start, String, :required => true
33 property :exec_start_post, String
34 property :exec_stop, String
35 property :exec_reload, String
36 property :restart, String,
37          :is => %w(on-success on-failure on-abnormal on-watchdog on-abort always)
38 property :timeout_sec, Fixnum
39
40 action :create do
41   template "/etc/systemd/system/#{name}.service" do
42     cookbook "systemd"
43     source "service.erb"
44     owner "root"
45     group "root"
46     mode 0644
47     variables new_resource.to_hash
48   end
49
50   execute "systemctl-reload-#{name}.service" do
51     action :nothing
52     command "systemctl daemon-reload"
53     user "root"
54     group "root"
55     subscribes :run, "template[/etc/systemd/system/#{name}.service]"
56   end
57 end
58
59 action :delete do
60   file "/etc/systemd/system/#{name}.service" do
61     action :delete
62   end
63
64   execute "systemctl-reload-#{name}.service" do
65     action :nothing
66     command "systemctl daemon-reload"
67     user "root"
68     group "root"
69     subscribes :run, "file[/etc/systemd/system/#{name}.service]"
70   end
71 end