问题描述
我正在使用https://supermarket.chef.io/cookbooks/tomcat上的食谱
instance_name = node['tomcat']['name']
# Install the Tomcat Service
tomcat_install instance_name do
version node['tomcat']['version']
dir_mode '0755'
install_path node['tomcat']['install_dir']
tarball_uri node['tomcat']['install_tar']
tomcat_user node['tomcat']['user']
tomcat_group node['tomcat']['group']
end
tomcat_service instance_name do
action [:start,:enable]
env_vars [{ 'CATALINA_PID' => '/opt/tomcat_helloworld/bin/non_standard_location.pid' },{ 'SOMETHING' => 'some_value' }]
sensitive true
end
我应该找到一个名为SOMETHING的环境变量,但是当我这样做的时候
echo $SOMETHING
我没有找到任何东西,也没有在#{derived_install_path} /bin/setenv.sh中找到setenv.sh 也带有此变量,但该文件不存在。
解决方法
env_vars
定制资源的tomcat_service
属性设置了Tomcat服务instance_name
的环境变量。 这些不是SHELL环境变量。
tomcat_service将已安装的tomcat实例设置为使用适当的init系统(sys-v,upstart或systemd)运行
在CentOS中,服务由systemctl
处理,因此这些变量被添加到相应的Systemd服务文件中。
示例:
/etc/systemd/system/tomcat_helloworld.service
剪切的内容:
Environment="CATALINA_BASE=/opt/tomcat_helloworld"
Environment="CATALINA_PID=/opt/tomcat_helloworld/bin/non_standard_location.pid"
Environment="SOMETHING=some_value"