Skip to content

Commit 2e32949

Browse files
committed
fix log4j
1 parent d69574b commit 2e32949

File tree

4 files changed

+58
-78
lines changed

4 files changed

+58
-78
lines changed

REFERENCE.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ The following parameters are available in the `elasticsearch` class:
129129
* [`license`](#-elasticsearch--license)
130130
* [`logdir`](#-elasticsearch--logdir)
131131
* [`logdir_mode`](#-elasticsearch--logdir_mode)
132+
* [`logging_content`](#-elasticsearch--logging_content)
132133
* [`manage_datadir`](#-elasticsearch--manage_datadir)
133134
* [`manage_logdir`](#-elasticsearch--manage_logdir)
134-
* [`manage_logging`](#-elasticsearch--manage_logging)
135135
* [`manage_repo`](#-elasticsearch--manage_repo)
136136
* [`oss`](#-elasticsearch--oss)
137137
* [`package_dir`](#-elasticsearch--package_dir)
@@ -399,6 +399,14 @@ Mode directory that will be used for Elasticsearch logging (default 2750).
399399

400400
Default value: `'2750'`
401401

402+
##### <a name="-elasticsearch--logging_content"></a>`logging_content`
403+
404+
Data type: `Optional[Variant[String, Array]]`
405+
406+
Content to use for the logging configuration file (log4j2.properties).
407+
408+
Default value: `undef`
409+
402410
##### <a name="-elasticsearch--manage_datadir"></a>`manage_datadir`
403411

404412
Data type: `Boolean`
@@ -411,14 +419,6 @@ Data type: `Boolean`
411419

412420
Enable logdir management (default true).
413421

414-
##### <a name="-elasticsearch--manage_logging"></a>`manage_logging`
415-
416-
Data type: `Boolean`
417-
418-
Enable logging (log4j) management (default false).
419-
420-
Default value: `false`
421-
422422
##### <a name="-elasticsearch--manage_repo"></a>`manage_repo`
423423

424424
Data type: `Boolean`

manifests/config.pp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,20 @@
142142
}
143143

144144
# Logging file
145-
if $elasticsearch::manage_logging and !empty($elasticsearch::logging_content) {
146-
file { $elasticsearch::logging_path:
145+
if ! ($elasticsearch::logging_content =~ Undef) {
146+
if $elasticsearch::logging_content =~ Array {
147+
$_log4j_content = $elasticsearch::logging_content.join("\n")
148+
} else {
149+
$_log4j_content = $elasticsearch::logging_content
150+
}
151+
file { "${elasticsearch::configdir}/log4j2.properties":
147152
ensure => file,
148-
content => $elasticsearch::logging_content,
149-
group => $elasticsearch::elasticsearch_group,
150-
owner => $elasticsearch::elasticsearch_user,
151-
mode => '0644',
153+
content => $_log4j_content,
152154
notify => $elasticsearch::_notify_service,
153-
require => File[$elasticsearch::configdir],
154-
before => Class['elasticsearch::service'],
155+
require => Class['elasticsearch::package'],
156+
owner => 'root',
157+
group => $elasticsearch::elasticsearch_group,
158+
mode => '0640',
155159
}
156160
}
157161

@@ -164,9 +168,9 @@
164168
content => template("${module_name}/etc/elasticsearch/elasticsearch.yml.erb"),
165169
notify => $elasticsearch::_notify_service,
166170
require => Class['elasticsearch::package'],
167-
owner => $elasticsearch::elasticsearch_user,
171+
owner => 'root',
168172
group => $elasticsearch::elasticsearch_group,
169-
mode => '0440',
173+
mode => '0640',
170174
}
171175

172176
file { "${elasticsearch::configdir}/jvm.options":

manifests/init.pp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@
133133
# @param logdir_mode
134134
# Mode directory that will be used for Elasticsearch logging (default 2750).
135135
#
136+
# @param logging_content
137+
# Content to use for the logging configuration file (log4j2.properties).
138+
#
136139
# @param manage_datadir
137140
# Enable datadir management (default true).
138141
#
139142
# @param manage_logdir
140143
# Enable logdir management (default true).
141144
#
142-
# @param manage_logging
143-
# Enable logging (log4j) management (default false).
144-
#
145145
# @param manage_repo
146146
# Enable repo management by enabling official Elastic repositories.
147147
#
@@ -378,9 +378,7 @@
378378
Optional[String] $keystore_password = undef,
379379
Optional[Stdlib::Absolutepath] $keystore_path = undef,
380380
Stdlib::Filemode $logdir_mode = '2750',
381-
Optional[String] $logging_content = undef,
382-
Stdlib::Absolutepath $logging_path = "${configdir}/log4j2.properties",
383-
Boolean $manage_logging = false,
381+
Optional[Variant[String, Array]] $logging_content = undef,
384382
Boolean $package_hold = false,
385383
Optional[Stdlib::Absolutepath] $private_key = undef,
386384
Enum['rsa','dsa','ec'] $private_key_type = 'rsa',

spec/classes/000_elasticsearch_init_spec.rb

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
}
8080
end
8181

82+
it { expect(subject).not_to contain_file('/etc/elasticsearch/log4j2.properties') }
83+
8284
context 'java installation' do
8385
let(:pre_condition) do
8486
<<-MANIFEST
@@ -346,6 +348,35 @@
346348
expect(subject).not_to contain_file('/var/log/elasticsearch-log')
347349
}
348350
end
351+
352+
context 'When using custom logging_content String' do
353+
let(:params) do
354+
default_params.merge(
355+
logging_content: '# Content'
356+
)
357+
end
358+
359+
it {
360+
expect(subject).to contain_file('/etc/elasticsearch/log4j2.properties').
361+
with(ensure: 'file', content: '# Content')
362+
}
363+
end
364+
365+
context 'When using custom logging_content Array' do
366+
let(:params) do
367+
default_params.merge(
368+
logging_content: [
369+
'# Content Line 1',
370+
'# Content Line 2',
371+
]
372+
)
373+
end
374+
375+
it {
376+
expect(subject).to contain_file('/etc/elasticsearch/log4j2.properties').
377+
with(ensure: 'file', content: "# Content Line 1\n# Content Line 2")
378+
}
379+
end
349380
end
350381
end
351382
# rubocop:enable RSpec/MultipleMemoizedHelpers
@@ -528,59 +559,6 @@
528559
}
529560
end
530561

531-
context 'When managing the logging file (with content)' do
532-
let(:params) do
533-
default_params.merge(
534-
logging_content: '# Content',
535-
manage_logging: true
536-
)
537-
end
538-
539-
it {
540-
expect(subject).to contain_file('/etc/elasticsearch/log4j2.properties').
541-
with(ensure: 'file', content: '# Content')
542-
}
543-
end
544-
545-
context 'When managing the logging file (with content and specific path)' do
546-
let(:params) do
547-
default_params.merge(
548-
logging_content: '# Content',
549-
logging_path: '/etc/elasticsearch/log4j.properties',
550-
manage_logging: true
551-
)
552-
end
553-
554-
it {
555-
expect(subject).to contain_file('/etc/elasticsearch/log4j.properties').
556-
with(ensure: 'file', content: '# Content')
557-
}
558-
end
559-
560-
context 'When managing the logging file (with no content)' do
561-
let(:params) do
562-
default_params.merge(
563-
manage_logging: true
564-
)
565-
end
566-
567-
it {
568-
expect(subject).not_to contain_file('/etc/elasticsearch/log4j2.properties')
569-
}
570-
end
571-
572-
context 'When not managing the logging file' do
573-
let(:params) do
574-
default_params.merge(
575-
manage_logging: false
576-
)
577-
end
578-
579-
it {
580-
expect(subject).not_to contain_file('/etc/elasticsearch/log4j2.properties')
581-
}
582-
end
583-
584562
context 'with restart_on_change => true' do
585563
let(:params) do
586564
default_params.merge(

0 commit comments

Comments
 (0)