java_webapp.rb 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. app = node.run_state['current_app']
  20. ###
  21. # You really most likely don't want to run this recipe from here - let the
  22. # default application recipe work it's mojo for you.
  23. ###
  24. node.default['apps'][app['id']][node.chef_environment]['run_migrations'] = false
  25. ## First, install any application specific packages
  26. if app['packages']
  27. app['packages'].each do |pkg,ver|
  28. package pkg do
  29. action :install
  30. version ver if ver && ver.length > 0
  31. end
  32. end
  33. end
  34. directory app['deploy_to'] do
  35. owner app['owner']
  36. group app['group']
  37. mode '0755'
  38. recursive true
  39. end
  40. directory "#{app['deploy_to']}/releases" do
  41. owner app['owner']
  42. group app['group']
  43. mode '0755'
  44. recursive true
  45. end
  46. directory "#{app['deploy_to']}/shared" do
  47. owner app['owner']
  48. group app['group']
  49. mode '0755'
  50. recursive true
  51. end
  52. %w{ log pids system }.each do |dir|
  53. directory "#{app['deploy_to']}/shared/#{dir}" do
  54. owner app['owner']
  55. group app['group']
  56. mode '0755'
  57. recursive true
  58. end
  59. end
  60. if app["database_master_role"]
  61. dbm = nil
  62. # If we are the database master
  63. if node.run_list.roles.include?(app["database_master_role"][0])
  64. dbm = node
  65. else
  66. # Find the database master
  67. results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
  68. rows = results[0]
  69. if rows.length == 1
  70. dbm = rows[0]
  71. end
  72. end
  73. # Assuming we have one...
  74. if dbm
  75. template "#{app['deploy_to']}/shared/#{app['id']}.xml" do
  76. source "context.xml.erb"
  77. owner app["owner"]
  78. group app["group"]
  79. mode "644"
  80. variables(
  81. :host => (dbm.attribute?('cloud') ? dbm['cloud']['local_ipv4'] : dbm['ipaddress']),
  82. :app => app['id'],
  83. :database => app['databases'][node.chef_environment],
  84. :war => "#{app['deploy_to']}/releases/#{app['war'][node.chef_environment]['checksum']}.war"
  85. )
  86. end
  87. end
  88. end
  89. ## Then, deploy
  90. remote_file app['id'] do
  91. path "#{app['deploy_to']}/releases/#{app['war'][node.chef_environment]['checksum']}.war"
  92. source app['war'][node.chef_environment]['source']
  93. mode "0644"
  94. checksum app['war'][node.chef_environment]['checksum']
  95. end