3 # Resource:: systemd_service
5 # Copyright:: 2016, OpenStreetMap Foundation
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
11 # https://www.apache.org/licenses/LICENSE-2.0
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.
22 default_action :create
24 property :service, String, :name_property => true
25 property :dropin, String
26 property :description, String
27 property :condition_path_exists, [String, Array]
28 property :condition_path_exists_glob, [String, Array]
29 property :after, [String, Array]
30 property :conflicts, [String, Array]
31 property :wants, [String, Array]
32 property :type, String, :is => %w[simple forking oneshot dbus notify idle]
33 property :limit_nofile, Integer
34 property :limit_as, [Integer, String]
35 property :limit_cpu, [Integer, String]
36 property :memory_low, [Integer, String]
37 property :memory_high, [Integer, String]
38 property :memory_max, [Integer, String]
39 property :environment, Hash, :default => {}
40 property :environment_file, [String, Hash]
41 property :user, String
42 property :group, String
43 property :working_directory, String
44 property :exec_start_pre, String
45 property :exec_start, String
46 property :exec_start_post, String
47 property :exec_stop, String
48 property :exec_reload, String
49 property :runtime_directory, String
50 property :runtime_directory_mode, Integer
51 property :runtime_max_sec, Integer
52 property :standard_input, String,
53 :is => %w[null tty tty-force tty-fail socket]
54 property :standard_output, String,
55 :is => %w[inherit null tty journal syslog kmsg journal+console syslog+console kmsg+console socket]
56 property :standard_error, String,
57 :is => %w[inherit null tty journal syslog kmsg journal+console syslog+console kmsg+console socket]
58 property :success_exit_status, [Integer, String, Array]
59 property :restart, String,
60 :is => %w[on-success on-failure on-abnormal on-watchdog on-abort always]
61 property :protect_proc, String,
62 :is => %w[noaccess invisible ptraceable default]
63 property :proc_subset, String,
65 property :capability_bounding_set, [String, Array]
66 property :no_new_privileges, [true, false]
67 property :protect_system, [true, false, String]
68 property :protect_home, [true, false, String]
69 property :read_write_paths, [String, Array]
70 property :read_only_paths, [String, Array]
71 property :inaccessible_paths, [String, Array]
72 property :private_tmp, [true, false]
73 property :private_devices, [true, false]
74 property :private_network, [true, false]
75 property :private_ipc, [true, false]
76 property :private_users, [true, false]
77 property :protect_hostname, [true, false]
78 property :protect_clock, [true, false]
79 property :protect_kernel_tunables, [true, false]
80 property :protect_kernel_modules, [true, false]
81 property :protect_kernel_logs, [true, false]
82 property :protect_control_groups, [true, false]
83 property :restrict_address_families, [String, Array]
84 property :restrict_namespaces, [true, false, String, Array]
85 property :lock_personality, [true, false]
86 property :memory_deny_write_execute, [true, false]
87 property :restrict_realtime, [true, false]
88 property :restrict_suid_sgid, [true, false]
89 property :remove_ipc, [true, false]
90 property :system_call_filter, [String, Array]
91 property :system_call_architectures, [String, Array]
92 property :tasks_max, Integer
93 property :timeout_start_sec, Integer
94 property :timeout_stop_sec, Integer
95 property :timeout_abort_sec, Integer
96 property :timeout_sec, Integer
97 property :pid_file, String
98 property :nice, Integer
99 property :io_scheduling_class, [Integer, String]
100 property :io_scheduling_priority, Integer
101 property :kill_mode, String,
102 :is => %w[control-group process mixed none]
105 service_variables = new_resource.to_hash
107 unless new_resource.dropin
108 service_variables[:type] ||= "simple"
111 if new_resource.environment_file.is_a?(Hash)
112 template "/etc/default/#{new_resource.service}" do
114 source "environment.erb"
118 variables :environment => new_resource.environment_file
121 service_variables[:environment_file] = "/etc/default/#{new_resource.service}"
124 if new_resource.dropin
125 directory dropin_directory do
132 template config_name do
138 variables service_variables
139 notifies :run, "execute[systemctl-reload]"
142 execute "systemctl-reload" do
144 command "systemctl daemon-reload"
151 file "/etc/default/#{new_resource.service}" do
153 only_if { new_resource.environment_file.is_a?(Hash) }
158 notifies :run, "execute[systemctl-reload]"
161 execute "systemctl-reload" do
163 command "systemctl daemon-reload"
171 "/etc/systemd/system/#{new_resource.service}.service.d"
175 if new_resource.dropin
176 "#{dropin_directory}/#{new_resource.dropin}.conf"
178 "/etc/systemd/system/#{new_resource.service}.service"