简体   繁体   English

使用Chef Java Cookbook时如何访问java_home

[英]How to access java_home when using Chef Java cookbook

To import a certificate in a keystore I want to access the attribute java/java_home . 要在密钥库中导入证书,我想访问属性java/java_home

On the Chef server I can manually read its value. 在Chef服务器上,我可以手动读取其值。 It shows up as /usr/lib/jvm/java-7-oracle-amd64 on the attribute tab. 在属性选项卡上,它显示为/usr/lib/jvm/java-7-oracle-amd64

Now I want to do the same in my Chef recipe. 现在我想在我的厨师食谱中做同样的事情。 When I inspect the node['java] it shows 当我检查node['java]它显示

node['java']: {"jdk_version"=>"7", "arch"=>"x86_64", "openjdk_packages"=>[], "openjdk_version"=>nil, "accept_license_agreement"=>false, "set_default"=>true, "alternatives_priority"=>1062, "set_etc_environment"=>false, "ark_retries"=>0, "ark_retry_delay"=>2, "install_flavor"=>"oracle", "oracle"=>{"accept_oracle_download_terms"=>true}, "jdk"=>{"6"=>{"bin_cmds"=>["appletviewer", "apt", "ControlPanel", "extcheck", "HtmlConverter", "idlj", "jar", "jarsigner", "java", "javac", "javadoc", "javah", "javap", "javaws", "jconsole", "jcontrol", "jdb", "jhat", "jinfo", "jmap", "jps", "jrunscript", "jsadebugd", "jstack", "jstat", "jstatd", "jvisualvm", "keytool", "native2ascii", "orbd", "pack200", "policytool", "rmic", "rmid", "rmiregistry", "schemagen", "serialver", "servertool", "tnameserv", "unpack200", "wsgen", "wsimport", "xjc"], "x86_64"=>{"url"=>"http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin", "checksum"=>"6b493aeab16c940cae9e3d07ad2a5c5684fb49cf06c5d44c400c7993db0d12e8"}, "i586"=>{"url"=>"http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin", "checksum"=>"d53b5a2518d80e1d95565f0adda54eee229dc5f4a1d1a3c2f7bf5045b168a357"}}, "7"=>{"bin_cmds"=>["appletviewer", "apt", "ControlPanel", "extcheck", "idlj", "jar", "jarsigner", "java", "javac", "javadoc", "javafxpackager", "javah", "javap", "javaws", "jcmd", "jconsole", "jcontrol", "jdb", "jhat", "jinfo", "jmap", "jps", "jrunscript", "jsadebugd", "jstack", "jstat", "jstatd", "jvisualvm", "keytool", "native2ascii", "orbd", "pack200", "policytool", "rmic", "rmid", "rmiregistry", "schemagen", "serialver", "servertool", "tnameserv", "unpack200", "wsgen", "wsimport", "xjc"], "x86_64"=>{"url"=>"http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.tar.gz", "checksum"=>"bea330fcbcff77d31878f21753e09b30"}, "i586"=>{"url"=>"http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-i586.tar.gz", "checksum"=>"54899d0733d9a8697da59de79a02cc8f"}}, "8"=>{"bin_cmds"=>["appletviewer", "apt", "ControlPanel", "extcheck", "idlj", "jar", "jarsigner", "java", "javac", "javadoc", "javafxpackager", "javah", "javap", "javaws", "jcmd", "jconsole", "jcontrol", "jdb", "jdeps", "jhat", "jinfo", "jjs", "jmap", "jmc", "jps", "jrunscript", "jsadebugd", "jstack", "jstat", "jstatd", "jvisualvm", "keytool", "native2ascii", "orbd", "pack200", "policytool", "rmic", "rmid", "rmiregistry", "schemagen", "serialver", "servertool", "tnameserv", "unpack200", "wsgen", "wsimport", "xjc"], "x86_64"=>{"url"=>"http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.tar.gz", "checksum"=>"e145c03a7edc845215092786bcfba77e"}, "i586"=>{"url"=>"http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-i586.tar.gz", "checksum"=>"b5b16247f66643727d9b6d4bc7c5efda"}}}}

Many of the attributes I see through the web interface are accesible but unfortunately java_home is not there. 我通过Web界面看到的许多属性都是可以访问的,但不幸的是java_home不存在。

Can I read this value through a Chef recipe? 我可以通过厨师食谱读取此值吗? Or is it only visible through the web interface? 还是仅通过Web界面可见?

Is there another way to know the location of Java? 还有另一种方法来知道Java的位置吗?

I tried environment variable $JAVA_HOME which used to work but recently I noticed that this is also now nil for a Chef client run. 我尝试使用曾经起作用的环境变量$JAVA_HOME ,但是最近我注意到,对于Chef客户端运行,现在也为零。

What is the correct way to import a certificate in a key store using Chef without being able to know the location of Java? 在不知道Java位置的情况下,使用Chef导入密钥存储中的证书的正确方法是什么?

在此处输入图片说明

If you're using the java cookbook , then the java_home should be made available at node['java']['java_home'] . 如果您使用的是Java Cookbook ,则应在node['java']['java_home'] That's what you should use in all your chef recipes, as long as they're run together with the java cookbook that will populate this value. 这就是您在所有厨师食谱中都应使用的内容,只要它们与将填充此值的Java食谱一起运行即可。

I presume you can't see the node['java']['java_home'] attribute in your inspection because you just haven't set it as a node attribute / environment attribute on the chef server. 我想您在检查中看不到node['java']['java_home']属性,因为您只是未在Chef服务器上将其设置为node属性/ environment属性。

For the $JAVA_HOME environment variable, you should set node['java']['set_etc_environment'] to true, (Optionally sets JAVA_HOME in /etc/environment, by default it's false). 对于$JAVA_HOME环境变量,应将node['java']['set_etc_environment']为true((可选地,在/ etc / environment中将JAVA_HOME设置为false)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM