Skip to content

Commit

Permalink
plugin/java: handle OpenJDK as well (#880)
Browse files Browse the repository at this point in the history
* plugin/java: handle OpenJDK as well

collectd-java requires:
* `libjvm.so()(64bit)`
* `libjvm.so(SUNWprivate_1.1)(64bit)`

On CentOS/RHEL 6.x/7.x these are provided by OpenJDK. OpenJDK stores the
JVM files in a bit of a different location: `amd64` has been removed
from the path. Thus, ATM the link does not get created properly on such
systems.

Fix this problem by adding two `exec` resources which both will try to
create the needed libjvm symbolic link. They are both smart and check if
that file exists before trying to execute. An assumption is added to the
code that both of the files cannot exist at the same time.

* plugin/java: add missing comma

* plugin/java: refactor into human-readable Exec resources

* spec/plugin_java: fix directory

* plugin/java: specify full paths

* plugin/java: ldconfig requires prior resources

* plugin/java: fix the order of ln arguments

* plugin/java: add missing comma
  • Loading branch information
GiedriusS committed Feb 8, 2020
1 parent 59fec59 commit 4612c19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 16 additions & 5 deletions manifests/plugin/java.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@
}
}
if $java_home {
file { '/usr/lib64/libjvm.so':
ensure => 'link',
target => "${java_home}/jre/lib/amd64/server/libjvm.so",
exec { 'Link libjvm.so on OpenJDK':
command => "/usr/bin/ln -s ${java_home}/jre/lib/server/libjvm.so /usr/lib64/libjvm.so",
creates => '/usr/lib64/libjvm.so',
onlyif => "/usr/bin/test -e ${java_home}/jre/lib/server/libjvm.so",
notify => Exec['/sbin/ldconfig'],
}

exec { 'Link libjvm.so on Oracle':
command => "/usr/bin/ln -s ${java_home}/jre/lib/amd64/server/libjvm.so /usr/lib64/libjvm.so",
creates => '/usr/lib64/libjvm.so',
onlyif => "/usr/bin/test -e ${java_home}/jre/lib/amd64/server/libjvm.so",
notify => Exec['/sbin/ldconfig'],
}

# Reload SO files so libjvm.so can be found
-> exec { '/sbin/ldconfig':
unless => '/sbin/ldconfig -p |grep libjvm.so >/dev/null 2>&1',
exec { '/sbin/ldconfig':
unless => '/sbin/ldconfig -p |grep libjvm.so >/dev/null 2>&1',
require => [Exec['Link libjvm.so on OpenJDK'], Exec['Link libjvm.so on Oracle']],
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions spec/classes/collectd_plugin_java_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
when 'RedHat'
context 'java_home option is empty' do
it 'will not contain libjvm' do
is_expected.not_to contain_file('/usr/lib64/libjvm.so')
is_expected.not_to contain_exec('Link libjvm.so on OpenJDK').with_onlyif('/usr/bin/test -e /bla/jre/lib/server/libjvm.so')
is_expected.not_to contain_exec('Link libjvm.so on Oracle').with_onlyif('/usr/bin/test -e /bla/jre/lib/amd64/server/libjvm.so')
is_expected.not_to contain_exec('/sbin/ldconfig')
end
end
Expand All @@ -132,7 +133,8 @@
end

it 'will contain libjvm' do
is_expected.to contain_file('/usr/lib64/libjvm.so')
is_expected.to contain_exec('Link libjvm.so on OpenJDK').with_onlyif('/usr/bin/test -e /bla/jre/lib/server/libjvm.so')
is_expected.to contain_exec('Link libjvm.so on Oracle').with_onlyif('/usr/bin/test -e /bla/jre/lib/amd64/server/libjvm.so')
is_expected.to contain_exec('/sbin/ldconfig')
end
end
Expand Down

0 comments on commit 4612c19

Please sign in to comment.