-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
service.rb
93 lines (76 loc) · 2.76 KB
/
service.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#
# Cookbook:: hashicorp-vault
# Resource:: service
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include Vault::Cookbook::Helpers
property :service_name, String,
coerce: proc { |p| "#{p}.service" },
default: lazy { default_vault_service_name },
description: 'Set to override service name. Defaults to vault.'
property :config_type, [Symbol, String],
coerce: proc { |p| p.to_sym },
equal_to: [:hcl, :json],
default: :hcl,
description: 'Vault configuration type used. Defaults to HCL.'
property :systemd_unit_content, [String, Hash],
default: lazy { default_vault_unit_content },
description: 'Override the systemd unit file contents'
property :vault_binary_path, String,
default: '/usr/bin/vault',
description: 'Path to the vault binary on disk.'
property :user, String,
default: lazy { default_vault_user },
description: 'Set to override default vault user. Defaults to vault.'
property :group, String,
default: lazy { default_vault_group },
description: 'Set to override default vault group. Defaults to vault.'
property :config_file, String,
default: lazy { default_vault_config_file(config_type) },
description: 'Set to override vault configuration file.'
property :mode, [String, Symbol],
coerce: proc { |p| p.to_sym },
equal_to: [:server, :agent],
default: :server,
description: 'Vault service operation mode. Defaults to server.'
action_class do
def do_service_action(resource_action)
with_run_context(:root) do
edit_resource(:service, new_resource.service_name.delete_suffix('.service')) do
supports status: true, restart: true, reload: true
action :nothing
delayed_action resource_action
end
end
end
end
action :create do
systemd_unit new_resource.service_name do
content new_resource.systemd_unit_content
triggers_reload true
action :create
end
end
action :delete do
do_service_action(:stop)
systemd_unit new_resource.name do
triggers_reload true
action :delete
end
end
%i(start stop restart reload enable disable).each do |service_action|
action service_action do
do_service_action(action)
end
end