Search code examples
rubytomcatchef-infrachef-recipe

Overriding attributes in chef


I have to modify the CATALINA OPTIONS of the linko cookbook. My problem is the attributes for catalina are set by a dependant cookbook (tomcat).

Here is the code that defines the catalina options in the dependant cookbook TOMCAT

 catalina_options   = Array.new
          catalina_options  << "-XX:+UseConcMarkSweepGC"
          catalina_options  << "-Xms#{new_resource.jvm_min_size}"
          catalina_options  << "-Xmx#{new_resource.jvm_max_size}"
          catalina_options  << "-XX:PermSize=#{new_resource.jvm_permsize}"
          catalina_options  << "-XX:MaxPermSize=#{new_resource.jvm_max_permsize}"

    template "#{new_resource.home}/bin/setenv.sh" do
            cookbook "ypg_tomcat"
            source "setenv.sh.erb"
            owner new_resource.user
            group new_resource.group
            variables({
               :java_home         => "/usr/lib/jvm/default-java",
               :java_options      => "#{java_options.join(' ')} #{new_resource.java_options}",
               :catalina_options1 => "#{catalina_options.join(' ')}",
               :catalina_options2 => "#{new_resource.catalina_options}",
               :classpath         => new_resource.classpath,
               :catalina_home     => "#{node[:ypg_tomcat][:home]}",
               :gc_opts           => "#{java_options.join(' ')} #{new_resource.gc_opts}",
               :solr_opts         => new_resource.solr_opts,
               :dcosp_running_env => new_resource.dcosp_running_env
            })
            notifies :restart, "service[#{new_resource.service_name}]"
          end

So i tried setting an override in my linko cookbook as follow : Content of the master.rb file :

if node[:yp_linko][:overwrite_gc]
  node.override['yp_linko']['catalina_options'] = node['yp_linko']['overwrite_gc']
end

And in my attribute file (default.rb) i added the parameters that i want :

default['yp_linko']['overwrite_gc'] = '-XX:+UseParallelGC -XX:+UseParallelOldGC'

Now when i run my teamcity project, i get the following parameters in my setenv.sh file for catalina :

CATALINA_OPTS="-XX:+UseConcMarkSweepGC -Xms12G -Xmx16G -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+DEFAULTRBOVERWRITE -javaagent:/var/lib/newrelic/tomcat/newrelic.jar

So somehow it still keeps the default values and adds my own parameters at the end instead of over riding them.

Thanks in advance for your help.


Solution

  • The ypg_tomcat cookbook is not public so we (outside of your company) have no way to know exactly what it is doing. But given that there is catalina_options1 and catalina_options2, I'm guessing the concat is internal, probably something like CATALINA_OPTS="<%= @catalina_options1 %> <%= @catalina_options2 %>" inside the template file. In which case stuff in 2 will always just be appended and you can't specifically override the stuff in 1 because it isn't from the node attribute in the first place.