default.rb 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #
  2. # Author:: Noah Kantrowitz <noah@opscode.com>
  3. # Cookbook Name:: application
  4. # Resource:: default
  5. #
  6. # Copyright:: 2011, Opscode, Inc <legal@opscode.com>
  7. #
  8. # Licensed under the Apache License, Version 2.0 (the "License");
  9. # you may not use this file except in compliance with the License.
  10. # You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. #
  20. require 'weakref'
  21. include Chef::Mixin::RecipeDefinitionDSLCore
  22. def initialize(*args)
  23. super
  24. @action = :deploy
  25. @sub_resources = []
  26. end
  27. actions :deploy, :remove
  28. attribute :id, :kind_of => String, :name_attribute => true
  29. attribute :environment_name, :kind_of => String, :default => (node.chef_environment =~ /_default/ ? "production" : node.chef_environment)
  30. attribute :path, :kind_of => String
  31. attribute :owner, :kind_of => String
  32. attribute :group, :kind_of => String
  33. attribute :revision, :kind_of => String
  34. attribute :repository, :kind_of => String
  35. attribute :environment, :kind_of => Hash, :default => {}
  36. attribute :deploy_key, :kind_of => [String, NilClass], :default => nil
  37. attribute :force, :kind_of => [TrueClass, FalseClass], :default => false
  38. attribute :purge_before_symlink, :kind_of => Array, :default => []
  39. attribute :create_dirs_before_symlink, :kind_of => Array, :default => []
  40. attribute :symlinks, :kind_of => Hash, :default => {}
  41. attribute :symlink_before_migrate, :kind_of => Hash, :default => {}
  42. attribute :migrate, :kind_of => [TrueClass, FalseClass], :default => false
  43. attribute :migration_command, :kind_of => [String, NilClass], :default => nil
  44. attribute :restart_command, :kind_of => [String, NilClass], :default => nil
  45. attribute :packages, :kind_of => [Array, Hash], :default => []
  46. attr_reader :sub_resources
  47. # Callback fires before deploy is started.
  48. def before_deploy(arg=nil, &block)
  49. arg ||= block
  50. set_or_return(:before_deploy, arg, :kind_of => [Proc, String])
  51. end
  52. # Callback fires before migration is run.
  53. def before_migrate(arg=nil, &block)
  54. arg ||= block
  55. set_or_return(:before_migrate, arg, :kind_of => [Proc, String])
  56. end
  57. # Callback fires before symlinking
  58. def before_symlink(arg=nil, &block)
  59. arg ||= block
  60. set_or_return(:before_symlink, arg, :kind_of => [Proc, String])
  61. end
  62. # Callback fires before restart
  63. def before_restart(arg=nil, &block)
  64. arg ||= block
  65. set_or_return(:before_restart, arg, :kind_of => [Proc, String])
  66. end
  67. # Callback fires after restart
  68. def after_restart(arg=nil, &block)
  69. arg ||= block
  70. set_or_return(:after_restart, arg, :kind_of => [Proc, String])
  71. end
  72. def method_missing(name, &block)
  73. begin
  74. resource = super("application_#{name.to_s}", id, &block)
  75. rescue NoMethodError
  76. resource = super(name, id, &block)
  77. end
  78. # Enforce action :nothing in case people forget
  79. resource.action :nothing
  80. # Make this a weakref to prevent a cycle between the application resource and the sub resources
  81. resource.application WeakRef.new(self)
  82. @sub_resources << resource
  83. resource
  84. end