]> git.openstreetmap.org Git - chef.git/blob - cookbooks/systemd/resources/service.rb
6221441018593e8eb04ee5add96ac10804caaec3
[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 :wants, [String, Array]
26 property :type, String,
27          :default => "simple",
28          :is => %w(simple forking oneshot dbus notify idle)
29 property :limit_nofile, Fixnum
30 property :environment, Hash, :default => {}
31 property :environment_file, String
32 property :user, String
33 property :group, String
34 property :exec_start_pre, String
35 property :exec_start, String, :required => true
36 property :exec_start_post, String
37 property :exec_stop, String
38 property :exec_reload, String
39 property :standard_input, String,
40          :is => %w(null tty tty-force tty-fail socket)
41 property :standard_output, String,
42          :is => %w(inherit null tty journal syslog kmsg journal+console syslog+console kmsg+console socket)
43 property :standard_error, String,
44          :is => %w(inherit null tty journal syslog kmsg journal+console syslog+console kmsg+console socket)
45 property :restart, String,
46          :is => %w(on-success on-failure on-abnormal on-watchdog on-abort always)
47 property :private_tmp, [TrueClass, FalseClass]
48 property :private_devices, [TrueClass, FalseClass]
49 property :private_network, [TrueClass, FalseClass]
50 property :protect_system, [TrueClass, FalseClass, String]
51 property :protect_home, [TrueClass, FalseClass, String]
52 property :timeout_sec, Fixnum
53 property :pid_file, String
54
55 action :create do
56   template "/etc/systemd/system/#{name}.service" do
57     cookbook "systemd"
58     source "service.erb"
59     owner "root"
60     group "root"
61     mode 0o644
62     variables new_resource.to_hash
63   end
64
65   execute "systemctl-reload-#{name}.service" do
66     action :nothing
67     command "systemctl daemon-reload"
68     user "root"
69     group "root"
70     subscribes :run, "template[/etc/systemd/system/#{name}.service]"
71   end
72 end
73
74 action :delete do
75   file "/etc/systemd/system/#{name}.service" do
76     action :delete
77   end
78
79   execute "systemctl-reload-#{name}.service" do
80     action :nothing
81     command "systemctl daemon-reload"
82     user "root"
83     group "root"
84     subscribes :run, "file[/etc/systemd/system/#{name}.service]"
85   end
86 end