Skip to content

Commit

Permalink
Merge pull request #1202 from phaedriel/jvm_options_owner
Browse files Browse the repository at this point in the history
Add owner/group to jvm.options file and Use jvm.options.d/jvm.options file by default
  • Loading branch information
h-haaks authored Feb 20, 2024
2 parents 0390edc + 618adbc commit 167ea14
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ elasticsearch::slm_policy { 'policiyname':

#### Add a new SLM policy using a file

This will install and/or replace the SLM ploicy in Elasticsearch:
This will install and/or replace the SLM policy in Elasticsearch:

```puppet
elasticsearch::slm_policy { 'policyname':
Expand Down Expand Up @@ -495,7 +495,7 @@ elasticsearch::ilm_policy { 'policiyname':

#### Add a new ILM policy using a file

This will install and/or replace the ILM ploicy in Elasticsearch:
This will install and/or replace the ILM policy in Elasticsearch:

```puppet
elasticsearch::ilm_policy { 'policyname':
Expand Down Expand Up @@ -526,7 +526,7 @@ elasticsearch::ilm_policy { 'policyname':
```
#### Delete an ILM policy

This will install and/or replace the ILM ploicy in Elasticsearch:
This will install and/or replace the ILM policy in Elasticsearch:

```puppet
elasticsearch::ilm_policy { 'policyname':
Expand Down
37 changes: 23 additions & 14 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,29 @@
mode => '0440',
}

if ($elasticsearch::version != false and versioncmp($elasticsearch::version, '7.7.0') >= 0) {
file { "${elasticsearch::configdir}/jvm.options":
ensure => 'file',
notify => $elasticsearch::_notify_service,
require => Class['elasticsearch::package'],
owner => 'root',
group => $elasticsearch::elasticsearch_group,
mode => '0640',
}

if ($elasticsearch::version != false and versioncmp($elasticsearch::version, '7.7.0') < 0) {
# Add any additional JVM options
$elasticsearch::jvm_options.each |String $jvm_option| {
$split_jvm_option = split($jvm_option, '=')
file_line { "jvm_option_${jvm_option}":
ensure => present,
path => "${elasticsearch::configdir}/jvm.options",
match => $split_jvm_option.length ? { 2 => "^${split_jvm_option[0]}=", default => undef, },
line => $jvm_option,
notify => $elasticsearch::_notify_service,
}
}
}
else {
# https://www.elastic.co/guide/en/elasticsearch/reference/master/advanced-configuration.html#set-jvm-options
# https://github.com/elastic/elasticsearch/pull/51882
# >> "Do not modify the root jvm.options file. Use files in jvm.options.d/ instead."
Expand All @@ -197,19 +219,6 @@
notify => $elasticsearch::_notify_service,
}
}
else {
# Add any additional JVM options
$elasticsearch::jvm_options.each |String $jvm_option| {
$split_jvm_option = split($jvm_option, '=')
file_line { "jvm_option_${jvm_option}":
ensure => present,
path => "${elasticsearch::configdir}/jvm.options",
match => $split_jvm_option.length ? { 2 => "^${split_jvm_option[0]}=", default => undef, },
line => $jvm_option,
notify => $elasticsearch::_notify_service,
}
}
}

if $elasticsearch::system_key != undef {
file { "${elasticsearch::configdir}/system_key":
Expand Down
7 changes: 6 additions & 1 deletion spec/classes/000_elasticsearch_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@
end
end

describe 'running a a different user' do
describe 'running a different user' do
let(:params) do
default_params.merge(
elasticsearch_user: 'myesuser',
Expand All @@ -464,6 +464,11 @@
expect(subject).to contain_file('/var/lib/elasticsearch').
with(owner: 'myesuser', group: 'myesgroup')
}

it {
expect(subject).to contain_file('/etc/elasticsearch/jvm.options').
with(owner: 'root', group: 'myesgroup')
}
end

describe 'setting jvm_options before version 7.7.0' do
Expand Down

0 comments on commit 167ea14

Please sign in to comment.