0

Recipe:

include_recipe "lgjava"
include_recipe "lgtomcat"


remote_file "/usr/local/tomcat7/webapps/web.war" do  #this file places web.war in the specified path
  source "http://path/to/web.war"
  action :create_if_missing
end


template "jdoconfig.xml" do
  source "jdoconfig.xml.erb"
  path "/usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF/jdoconfig.xml"
  action :create_if_missing
  mode "0755"
end

template "appname.properties" do
  source "appname.properties.erb"
  path "/usr/local/tomcat7/webapps/web/WEB-INF/classes/appname.properties"
  action :create_if_missing
  mode "0755"
end

Execution:

 Recipe: lgwebapp::default

  * remote_file[/usr/local/tomcat7/webapps/web.war] action create_if_missing
    - create new file /usr/local/tomcat7/webapps/web.war
    - update content in file /usr/local/tomcat7/webapps/web.war from none to ac4b77
    (file sizes exceed 10000000 bytes, diff output suppressed)
    - restore selinux security context

  * template[jdoconfig.xml] action create_if_missing
    * Parent directory /usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF does not exist.

    ================================================================================
    Error executing action `create_if_missing` on resource 'template[jdoconfig.xml]'
    ================================================================================

    Chef::Exceptions::EnclosingDirectoryDoesNotExist
    ------------------------------------------------
    Parent directory /usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF does not exist.

    Resource Declaration:
    ---------------------
    # In /var/chef/cache/cookbooks/lgwebapp/recipes/default.rb

         20: template "jdoconfig.xml" do
         21:   source "jdoconfig.xml.erb"
         22:   path "/usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF/jdoconfig.xml"
         23:   action :create_if_missing
         24:   mode "0755"
         25: end
         26: 

    Compiled Resource:
    ------------------
        # Declared in /var/chef/cache/cookbooks/lgwebapp/recipes/default.rb:20:in `from_file'

        template("jdoconfig.xml") do
          provider Chef::Provider::Template
          action [:create_if_missing]
          retries 0
          retry_delay 2
          guard_interpreter :default
          path "/usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF/jdoconfig.xml"
          backup 5
          atomic_update true
          source "jdoconfig.xml.erb"
          cookbook_name "lgwebapp"
          recipe_name "default"
          mode "0755"
        end

Recipe: lgtomcat::default
  * service[tomcat7] action restart
    - restart service service[tomcat7]

Running handlers:
[2015-01-14T10:38:44+00:00] ERROR: Running exception handlers
Running handlers complete

[2015-01-14T10:38:44+00:00] ERROR: Exception handlers complete

[2015-01-14T10:38:44+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 6 resources updated in 6.532117395 seconds

[2015-01-14T10:38:44+00:00] ERROR: template[jdoconfig.xml] (lgwebapp::default line 20) had an error: Chef::Exceptions::EnclosingDirectoryDoesNotExist: Parent directory /usr/local/tomcat7/webapps/web/WEB-INF/classes/META-INF does not exist.

[2015-01-14T10:38:44+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

P.S: the web.war file is deployed under tomcat7/webapps and its extracted too. I manually checked it, the file exists in the specific location. Why is that it's not able to locate using 'templates'?

Tensibai
  • 15,557
  • 1
  • 37
  • 57
Shaik Sadiq Ahmed
  • 173
  • 1
  • 4
  • 18

2 Answers2

1

Take it as stream:

Chef deploys the war then renders the template and try to compare with existing file.

The problem is that when chef tries to get the target file info, Tomcat probably has not yet unpacked the war file at all.

We do this kind of deployment with an ark resource out of tomcat, render the templates and then copy or link (depending on the cases) the temp deploy dir to the webapps tomcat dir.

Konstantin Kolinko
  • 3,854
  • 1
  • 13
  • 21
Tensibai
  • 15,557
  • 1
  • 37
  • 57
0

The below code solved my problem:

ruby_block 'wait for tomcat' do
  block do
   true until ::File.exists?("#{node['webapp']['webinf_dir']}")
  end
end
Shaik Sadiq Ahmed
  • 173
  • 1
  • 4
  • 18
  • You should avoid looping forever like this, use a counter, a sleep time, and include the counter in the loop condition (not mentionning you may be slowing down you deployment with this loop, consuming a cpu core while waiting). – Tensibai Jan 19 '15 at 10:53
  • Thanks @Tensibai I will try to modify this – Shaik Sadiq Ahmed Jan 22 '15 at 06:32