chef-infra - 无法使用 Chef Tomcat 设置环境变量
问题描述
我正在使用来自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"
推荐阅读
- java - 使用 Eclipse 使用 Maven 运行 Cucumber 测试导致多个 Chrome 窗口打开,并且不会关闭
- airflow - 气流 2 - ModuleNotFoundError:没有名为“airflow.operators.sensors”的模块
- node.js - 我不能在角度服务中传递两个参数来将 roomId 和 file_name 参数发送到 nodejs
- c - 为什么 libc 依赖 ld.so?
- python - 如何更新/安装 gcovr 以匹配我更新的编译器 gcc
- sql - 访问 - 从另一个 Combobox 填充的 Combobox 选择列表中的第一项
- mybatis - 如何用mybatis注解多对一
- angular - “ionic cordova build browser”和“ng build”有什么区别?
- python - 如何使用 Python 和 Pandas 将 csv 文件中一个单元格的值复制到另一个 csv 文件?
- javascript - 不同数组的Javascript md5哈希产生相同的值