chef-infratomcat8cookbook

Unable to set environment variables using Chef tomcat


I am using a cookbook from 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

I am expected to find an env variable named SOMETHING, but when I do

echo $SOMETHING

I don't find any, also I don't find the setenv.sh in #{derived_install_path}/bin/setenv.sh with this variable as well, but this file does not exist.


Solution

  • The env_vars property of tomcat_service custom resource sets the environment variables for the Tomcat service instance_name. These are not SHELL environment variables.

    tomcat_service sets up the installed tomcat instance to run using the appropriate init system (sys-v, upstart, or systemd)

    In CentOS services are handled by systemctl and hence these variables are added in the respective Systemd service file.

    Example:

    /etc/systemd/system/tomcat_helloworld.service
    

    Snipped contents:

    Environment="CATALINA_BASE=/opt/tomcat_helloworld"
    Environment="CATALINA_PID=/opt/tomcat_helloworld/bin/non_standard_location.pid"
    Environment="SOMETHING=some_value"