Skip to content

Commit 479d851

Browse files
committed
Fixes
Signed-off-by: Dan Webb <[email protected]>
1 parent 13312f7 commit 479d851

File tree

6 files changed

+43
-78
lines changed

6 files changed

+43
-78
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require:
2+
- cookstyle

Dangerfile

Lines changed: 0 additions & 47 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ a matching `elasticsearch_config` resource in the collection.
232232
elasticsearch_service 'elasticsearch'
233233
```
234234

235-
**Restart Configuration**
235+
#### Restart Configuration
236236

237237
You can configure systemd restart behavior using the `restart_policy` and `restart_sec` properties:
238238

mise.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# .mise.toml
2+
3+
[env]
4+
PATH = "/opt/chef-workstation/bin:/opt/chef-workstation/embedded/bin:{{env.PATH}}"
5+
KITCHEN_LOCAL_YAML = "kitchen.dokken.yml"

resources/service.rb

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,38 @@
4040

4141
default_conf_dir = platform_family?('rhel', 'amazon') ? '/etc/sysconfig' : '/etc/default'
4242

43+
service_config = {
44+
Type: 'notify',
45+
RuntimeDirectory: 'elasticsearch',
46+
PrivateTmp: 'true',
47+
Environment: [
48+
"ES_HOME=#{es_conf.path_home}",
49+
'ES_PATH_CONF=/etc/elasticsearch',
50+
"PID_DIR=#{es_conf.path_pid}",
51+
'ES_SD_NOTIFY=true',
52+
],
53+
EnvironmentFile: "-#{default_conf_dir}/#{new_resource.service_name}",
54+
WorkingDirectory: es_conf.path_home.to_s,
55+
User: es_user.username,
56+
Group: es_user.groupname,
57+
ExecStart: "#{es_conf.path_home}/bin/systemd-entrypoint -p ${PID_DIR}/elasticsearch.pid --quiet",
58+
StandardOutput: 'journal',
59+
StandardError: 'inherit',
60+
LimitNOFILE: '65535',
61+
LimitNPROC: '4096',
62+
LimitAS: 'infinity',
63+
LimitFSIZE: 'infinity',
64+
TimeoutStopSec: '0',
65+
KillSignal: 'SIGTERM',
66+
KillMode: 'process',
67+
SendSIGKILL: 'no',
68+
SuccessExitStatus: '143',
69+
TimeoutStartSec: '900',
70+
}
71+
72+
service_config[:Restart] = new_resource.restart_policy if new_resource.restart_policy && !new_resource.restart_policy.empty?
73+
service_config[:RestartSec] = new_resource.restart_sec if new_resource.restart_sec
74+
4375
systemd_unit new_resource.service_name do
4476
content(
4577
Unit: {
@@ -48,36 +80,7 @@
4880
Wants: 'network-online.target',
4981
After: 'network-online.target',
5082
},
51-
Service: {
52-
Type: 'notify',
53-
RuntimeDirectory: 'elasticsearch',
54-
PrivateTmp: 'true',
55-
Environment: [
56-
"ES_HOME=#{es_conf.path_home}",
57-
'ES_PATH_CONF=/etc/elasticsearch',
58-
"PID_DIR=#{es_conf.path_pid}",
59-
'ES_SD_NOTIFY=true',
60-
],
61-
EnvironmentFile: "-#{default_conf_dir}/#{new_resource.service_name}",
62-
WorkingDirectory: "#{es_conf.path_home}",
63-
User: es_user.username,
64-
Group: es_user.groupname,
65-
ExecStart: "#{es_conf.path_home}/bin/systemd-entrypoint -p ${PID_DIR}/elasticsearch.pid --quiet",
66-
StandardOutput: 'journal',
67-
StandardError: 'inherit',
68-
LimitNOFILE: '65535',
69-
LimitNPROC: '4096',
70-
LimitAS: 'infinity',
71-
LimitFSIZE: 'infinity',
72-
TimeoutStopSec: '0',
73-
KillSignal: 'SIGTERM',
74-
KillMode: 'process',
75-
SendSIGKILL: 'no',
76-
SuccessExitStatus: '143',
77-
TimeoutStartSec: '900',
78-
Restart: new_resource.restart_policy if new_resource.restart_policy,
79-
RestartSec: new_resource.restart_sec if new_resource.restart_sec
80-
},
83+
Service: service_config,
8184
Install: {
8285
WantedBy: 'multi-user.target',
8386
}

spec/service_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
end
3434

3535
# Test default behavior (no restart)
36+
# rubocop:disable Style/MultilineBlockChain
3637
context 'with default configuration' do
3738
let(:chef_run) do
3839
ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '20.04', step_into: ['elasticsearch_service']) do |node, server|
@@ -54,4 +55,5 @@
5455
expect(systemd_unit.content[:Service]).not_to have_key(:RestartSec)
5556
end
5657
end
58+
# rubocop:enable Style/MultilineBlockChain
5759
end

0 commit comments

Comments
 (0)