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. 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. if Chef::Config[:solo]
  67. Chef::Log.warn("This recipe uses search. Chef Solo does not support search.")
  68. else
  69. # Find the database master
  70. results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
  71. rows = results[0]
  72. if rows.length == 1
  73. dbm = rows[0]
  74. end
  75. end
  76. end
  77. template "#{app['deploy_to']}/shared/#{app['id']}.xml" do
  78. source "context.xml.erb"
  79. owner app["owner"]
  80. group app["group"]
  81. mode "644"
  82. variables(
  83. :host => (dbm.attribute?('cloud') ? dbm['cloud']['local_ipv4'] : dbm['ipaddress']),
  84. :app => app['id'],
  85. :database => app['databases'][node.chef_environment],
  86. :war => "#{app['deploy_to']}/releases/#{app['war'][node.chef_environment]['checksum']}.war"
  87. )
  88. only_if { dbm } # Assuming we have one...
  89. end
  90. end
  91. ## Then, deploy
  92. remote_file app['id'] do
  93. path "#{app['deploy_to']}/releases/#{app['war'][node.chef_environment]['checksum']}.war"
  94. source app['war'][node.chef_environment]['source']
  95. mode "0644"
  96. checksum app['war'][node.chef_environment]['checksum']
  97. end