java_webapp.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #
  2. # Cookbook Name:: application
  3. # Recipe:: java_webapp
  4. #
  5. # Copyright 2010-2011, Opscode, Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. Chef::Log.warn "The application::java_webapp recipe is deprecated and will go away on Aug 1st. See the README for migration information."
  20. app = node.run_state[:current_app]
  21. ###
  22. # You really most likely don't want to run this recipe from here - let the
  23. # default application recipe work it's mojo for you.
  24. ###
  25. node.default[:apps][app['id']][node.chef_environment][:run_migrations] = false
  26. ## First, install any application specific packages
  27. if app['packages']
  28. app['packages'].each do |pkg,ver|
  29. package pkg do
  30. action :install
  31. version ver if ver && ver.length > 0
  32. end
  33. end
  34. end
  35. directory app['deploy_to'] do
  36. owner app['owner']
  37. group app['group']
  38. mode '0755'
  39. recursive true
  40. end
  41. directory "#{app['deploy_to']}/releases" do
  42. owner app['owner']
  43. group app['group']
  44. mode '0755'
  45. recursive true
  46. end
  47. directory "#{app['deploy_to']}/shared" do
  48. owner app['owner']
  49. group app['group']
  50. mode '0755'
  51. recursive true
  52. end
  53. %w{ log pids system }.each do |dir|
  54. directory "#{app['deploy_to']}/shared/#{dir}" do
  55. owner app['owner']
  56. group app['group']
  57. mode '0755'
  58. recursive true
  59. end
  60. end
  61. if app["database_master_role"]
  62. dbm = nil
  63. # If we are the database master
  64. if node.run_list.roles.include?(app["database_master_role"][0])
  65. dbm = node
  66. else
  67. # Find the database master
  68. results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
  69. rows = results[0]
  70. if rows.length == 1
  71. dbm = rows[0]
  72. end
  73. end
  74. # Assuming we have one...
  75. if dbm
  76. template "#{app['deploy_to']}/shared/#{app['id']}.xml" do
  77. source "context.xml.erb"
  78. owner app["owner"]
  79. group app["group"]
  80. mode "644"
  81. variables(
  82. :host => (dbm.attribute?('cloud') ? dbm['cloud']['local_ipv4'] : dbm['ipaddress']),
  83. :app => app['id'],
  84. :database => app['databases'][node.chef_environment],
  85. :war => "#{app['deploy_to']}/releases/#{app['war'][node.chef_environment]['checksum']}.war"
  86. )
  87. end
  88. end
  89. end
  90. ## Then, deploy
  91. remote_file app['id'] do
  92. path "#{app['deploy_to']}/releases/#{app['war'][node.chef_environment]['checksum']}.war"
  93. source app['war'][node.chef_environment]['source']
  94. mode "0644"
  95. checksum app['war'][node.chef_environment]['checksum']
  96. end