add two facts: java_libjvm_path java_default_home
* dirname containing base directory of java
* e.g. java binary is `${::java_default_home}/jre/bin/java`
* dirname containing `libjvm.so`
* Most people will use this for LD_LIBRARY_PATH
This commit is contained in:
21
lib/facter/java_default_home.rb
Normal file
21
lib/facter/java_default_home.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
# Fact: java_default_home
|
||||
#
|
||||
# Purpose: get absolute path of java system home
|
||||
#
|
||||
# Resolution:
|
||||
# Uses `readlink` to resolve the path of `/usr/bin/java` then returns subsubdir
|
||||
#
|
||||
# Caveats:
|
||||
# Requires readlink
|
||||
#
|
||||
# Notes:
|
||||
# None
|
||||
Facter.add(:java_default_home) do
|
||||
confine :kernel => 'Linux'
|
||||
setcode do
|
||||
if Facter::Util::Resolution.which('readlink')
|
||||
java_bin = Facter::Util::Resolution.exec('readlink -e /usr/bin/java').strip
|
||||
java_default_home = File.dirname(File.dirname(File.dirname(java_bin)))
|
||||
end
|
||||
end
|
||||
end
|
||||
25
lib/facter/java_libjvm_path.rb
Normal file
25
lib/facter/java_libjvm_path.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
# Fact: java_libjvm_path
|
||||
#
|
||||
# Purpose: get path to libjvm.so
|
||||
#
|
||||
# Resolution:
|
||||
# Lists file in java default home and searches for the file
|
||||
#
|
||||
# Caveats:
|
||||
# Needs to list files recursively. Returns the first match
|
||||
#
|
||||
# Notes:
|
||||
# None
|
||||
Facter.add(:java_libjvm_path) do
|
||||
confine :kernel => "Linux"
|
||||
setcode do
|
||||
java_default_home = Facter.value(:java_default_home)
|
||||
java_libjvm_file = Dir.glob("#{java_default_home}/jre/lib/**/libjvm.so")
|
||||
if java_libjvm_file.nil? || java_libjvm_file.empty?
|
||||
nil
|
||||
else
|
||||
File.dirname(java_libjvm_file[0])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user