【问题标题】:Unable to set environment variables using Chef tomcat无法使用 Chef Tomcat 设置环境变量
【发布时间】:2020-08-21 15:18:12
【问题描述】:

我正在使用来自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 也有这个变量,但是这个文件不存在。

【问题讨论】:

  • tomcat_service 的行为可能因 Linux 发行版而异。您使用的是哪个发行版?
  • 我使用的是 Centos 7

标签: chef-infra tomcat8 cookbook


【解决方案1】:

tomcat_service 自定义资源的env_vars 属性设置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"

【讨论】:

    猜你喜欢
    • 2013-06-30
    • 2015-10-21
    • 2011-09-11
    • 2012-10-08
    • 1970-01-01
    • 2018-07-20
    • 2018-10-15
    • 2011-09-21
    • 2018-11-28
    相关资源
    最近更新 更多