/cookbooks/db/resources/default.rb

https://github.com/urtak/cookbooks_public · Ruby · 222 lines · 45 code · 35 blank · 142 comment · 0 complexity · 736eb0b377846c3ecab9ca9a5446e0fa MD5 · raw file

  1. #
  2. # Cookbook Name:: db
  3. #
  4. # Copyright RightScale, Inc. All rights reserved. All access and use subject to the
  5. # RightScale Terms of Service available at http://www.rightscale.com/terms.php and,
  6. # if applicable, other agreements such as a RightScale Master Subscription Agreement.
  7. # Add actions to @action_list array.
  8. # Used to allow comments between entries.
  9. def self.add_action(sym)
  10. @action_list ||= Array.new
  11. @action_list << sym unless @action_list.include?(sym)
  12. @action_list
  13. end
  14. # = Database Attributes
  15. #
  16. # Below are the attributes defined by the db resource interface.
  17. #
  18. # == General options
  19. attribute :user, :kind_of => String, :default => "root"
  20. attribute :password, :kind_of => String, :default => ""
  21. attribute :data_dir, :kind_of => String, :default => "/mnt/storage"
  22. # == Backup/Restore options
  23. attribute :lineage, :kind_of => String
  24. attribute :force, :kind_of => String, :default => "false"
  25. attribute :timestamp_override, :kind_of => String, :default => nil
  26. attribute :from_master, :kind_of => String, :default => nil
  27. # == Privilege options
  28. attribute :privilege, :equal_to => [ "administrator", "user" ], :default => "administrator"
  29. attribute :privilege_username, :kind_of => String
  30. attribute :privilege_password, :kind_of => String
  31. attribute :privilege_database, :kind_of => String, :default => "*.*" # All databases
  32. # == Firewall options
  33. attribute :enable, :equal_to => [ true, false ], :default => true
  34. attribute :ip_addr, :kind_of => String
  35. attribute :machine_tag, :kind_of => String, :regex => /^([^:]+):(.+)=.+/
  36. # == Import/Export options
  37. attribute :dumpfile, :kind_of => String
  38. attribute :db_name, :kind_of => String
  39. # = General Database Actions
  40. #
  41. # Below are the actions defined by by the db resource interface.
  42. #
  43. # == Stop
  44. # Stop the database service.
  45. #
  46. # Calls the correct init.d script for the database and platform.
  47. #
  48. add_action :stop
  49. # == Start
  50. # Start the database service.
  51. #
  52. # Calls the correct init.d script for the database and platform.
  53. #
  54. add_action :start
  55. # == Status
  56. # Log the status of the database service.
  57. #
  58. # Calls the correct init.d script for the database and platform
  59. # and send the output to the Chef log and RightScale audit entries.
  60. #
  61. add_action :status
  62. # == Lock
  63. # Lock the database so writes will be blocked.
  64. #
  65. # This must insure a conistent state while taking a snapshot.
  66. #
  67. add_action :lock
  68. # == Unlock
  69. # Unlock the database so writes can occur.
  70. #
  71. # This must be called as soon as possible after calling the :lock action
  72. # since no clients will be blocked from writting.
  73. #
  74. add_action :unlock
  75. # == Reset
  76. # Wipes the current database into a pristine state.
  77. #
  78. # This utility action can be useful in development and test environments.
  79. # Not recommended for production use.
  80. #
  81. # WARNING: this will delete any data in your database!
  82. #
  83. add_action :reset
  84. # == Firewall Update
  85. # Updates database firewall rules.
  86. #
  87. add_action :firewall_update
  88. # == Firewall Update Request
  89. # Sends a remote_recipe that requests a database updates it's firewall rules.
  90. #
  91. add_action :firewall_update_request
  92. # == Move Data Directory
  93. # Relocate the database data directory
  94. #
  95. # Moves the data directory from the default install path to the path specified
  96. # in name attribute or data_dir attribute of the resource. This is used for
  97. # relocating the data directory to a block device that provides snapshot
  98. # functionality.
  99. #
  100. # This action should also setup a symlink from the old path to the new
  101. # location.
  102. #
  103. add_action :move_data_dir
  104. # == Generate dump file
  105. add_action :generate_dump_file
  106. # == restore db from dump file
  107. add_action :restore_from_dump_file
  108. # == Pre-backup Check
  109. # Verify the database is in a good state for taking a snapshot.
  110. #
  111. # This action is used to verify correct state and to preform any
  112. # other steps necessary before the database is locked.
  113. #
  114. # This action should raise an exception if the database is not
  115. # in a valid state for a backup.
  116. #
  117. add_action :pre_backup_check
  118. # == Post-backup Cleanup
  119. # Used to cleanup VM after backup.
  120. #
  121. # This action is called after the backup has completed. Can be used to cleanup
  122. # any temporary files created from the :pre_backup_check action.
  123. #
  124. add_action :post_backup_cleanup
  125. # == Write Backup Info
  126. # TODO
  127. add_action :write_backup_info
  128. # == Pre-restore Check
  129. # Verify the database is in a good state before preforming a restore.
  130. #
  131. # This action is called before a restore is performed. It should be used to
  132. # verify that the system is in a correct state for restoring and should
  133. # preform any other steps necessary before a new block_device is attached
  134. # and the database is stopped for a restore.
  135. #
  136. # This action should raise an exception if the database is not
  137. # in a valid state for a restore.
  138. #
  139. add_action :pre_restore_check
  140. # == Post-restore Cleanup
  141. # Used to cleanup VM after restore.
  142. #
  143. # This action is called after the block_device restore has completed and
  144. # before the database is started.
  145. #
  146. # Used to link the database to the files in the newly restored data_dir.
  147. # Can also be used to perform other steps necessary to cleanup after a
  148. # restore.
  149. #
  150. add_action :post_restore_cleanup
  151. # == Set Privileges
  152. # Set database user privileges.
  153. #
  154. # Use the privilage attributes of this resource to setup 'administrator' or
  155. # 'user' privilages to the given username with the given password.
  156. #
  157. add_action :set_privileges
  158. # == Install Client
  159. # Installs database client
  160. #
  161. # Use to install the client on any system that needs to connect to the server.
  162. # Also should install language binding packages For example, ruby client gem
  163. # java client jar, php client modules, etc
  164. #
  165. add_action :install_client
  166. # == Install Server
  167. # Installs database server
  168. #
  169. add_action :install_server
  170. # == Setup Monitoring
  171. # Install and configure collectd plgins for the server.
  172. #
  173. # This is used by the RightScale platorm to display metrics about the database
  174. # on the RightScale dashboard. Also enables alerts and escalations for the
  175. # database.
  176. #
  177. add_action :setup_monitoring
  178. # == Enable Replication
  179. # Configures and start a slave replicating from master
  180. add_action :enable_replication
  181. # == Promote
  182. # TODO
  183. add_action :promote
  184. # == Grant Replication Slave
  185. # TODO
  186. add_action :grant_replication_slave
  187. actions @action_list