rubber 1.3.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. data/CHANGELOG +7 -0
  2. data/VERSION +1 -1
  3. data/bin/vulcanize +16 -32
  4. data/generators/vulcanize/templates/apache/config/rubber/deploy-apache.rb +6 -6
  5. data/generators/vulcanize/templates/apache/config/rubber/role/apache/monit-apache.conf +2 -2
  6. data/generators/vulcanize/templates/apache/config/rubber/role/apache/ports.conf +3 -0
  7. data/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-apache-vhost.conf +29 -16
  8. data/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-index.html +1 -1
  9. data/generators/vulcanize/templates/base/Rakefile +21 -0
  10. data/generators/vulcanize/templates/base/config/rubber/common/crontab +6 -1
  11. data/generators/vulcanize/templates/base/config/rubber/common/monit-postfix.conf +2 -2
  12. data/generators/vulcanize/templates/base/config/rubber/common/rubber.profile +3 -4
  13. data/generators/vulcanize/templates/base/config/rubber/deploy-setup.rb +27 -48
  14. data/generators/vulcanize/templates/base/config/rubber/deploy-util.rb +97 -0
  15. data/generators/vulcanize/templates/base/config/rubber/rubber-rvm.yml +25 -0
  16. data/generators/vulcanize/templates/base/config/rubber/rubber.yml +7 -12
  17. data/generators/vulcanize/templates/base/script/cron-runner +1 -1
  18. data/generators/vulcanize/templates/base/templates.rb +9 -0
  19. data/generators/vulcanize/templates/base/templates.yml +5 -0
  20. data/generators/vulcanize/templates/cassandra/config/rubber/deploy-cassandra.rb +88 -0
  21. data/generators/vulcanize/templates/cassandra/config/rubber/role/cassandra/cassandra.in.sh +58 -0
  22. data/generators/vulcanize/templates/cassandra/config/rubber/role/cassandra/cassandra.yaml +210 -0
  23. data/generators/vulcanize/templates/cassandra/config/rubber/role/cassandra/log4j-server.properties +45 -0
  24. data/generators/vulcanize/templates/cassandra/config/rubber/role/cassandra/monit-cassandra.conf +8 -0
  25. data/generators/vulcanize/templates/cassandra/config/rubber/rubber-cassandra.yml +18 -0
  26. data/generators/vulcanize/templates/cassandra/templates.yml +1 -0
  27. data/generators/vulcanize/templates/{complete_passenger_mysql → complete_passenger}/config/rubber/role/haproxy/haproxy-passenger.conf +1 -1
  28. data/generators/vulcanize/templates/{complete_passenger_mysql → complete_passenger}/config/rubber/rubber-complete.yml +0 -0
  29. data/generators/vulcanize/templates/complete_passenger/templates.rb +9 -0
  30. data/generators/vulcanize/templates/complete_passenger/templates.yml +9 -0
  31. data/generators/vulcanize/templates/complete_passenger_mysql/templates.yml +1 -7
  32. data/generators/vulcanize/templates/complete_passenger_postgresql/templates.yml +4 -0
  33. data/generators/vulcanize/templates/cruise/config/rubber/deploy-cruise.rb +3 -3
  34. data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/my.cnf +1 -1
  35. data/generators/vulcanize/templates/haproxy/config/rubber/deploy-haproxy.rb +5 -5
  36. data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/monit-haproxy.conf +2 -2
  37. data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/syslog-haproxy.conf +1 -1
  38. data/generators/vulcanize/templates/jetty/config/rubber/deploy-jetty.rb +4 -4
  39. data/generators/vulcanize/templates/memcached/config/rubber/role/memcached/memcached.conf +1 -1
  40. data/generators/vulcanize/templates/mongrel/config/rubber/deploy-mongrel.rb +4 -4
  41. data/generators/vulcanize/templates/monit/config/rubber/common/monit.conf +2 -0
  42. data/generators/vulcanize/templates/monit/config/rubber/deploy-monit.rb +3 -3
  43. data/generators/vulcanize/templates/munin/config/rubber/common/monit-munin.conf +2 -2
  44. data/generators/vulcanize/templates/munin/config/rubber/common/munin-node.conf +1 -1
  45. data/generators/vulcanize/templates/munin/config/rubber/common/munin-plugins.conf +4 -2
  46. data/generators/vulcanize/templates/munin/config/rubber/deploy-munin.rb +4 -4
  47. data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin-plugins.conf +2 -2
  48. data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin.conf +1 -0
  49. data/generators/vulcanize/templates/munin/config/rubber/rubber-munin.yml +1 -1
  50. data/generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb +6 -8
  51. data/generators/vulcanize/templates/mysql/config/rubber/common/database.yml +1 -0
  52. data/generators/vulcanize/templates/mysql/config/rubber/deploy-mysql.rb +24 -109
  53. data/generators/vulcanize/templates/mysql/config/rubber/role/db/apparmor-mysql.conf +1 -1
  54. data/generators/vulcanize/templates/mysql/config/rubber/role/db/monit-mysql.cnf +2 -2
  55. data/generators/vulcanize/templates/mysql/config/rubber/rubber-mysql.yml +1 -1
  56. data/generators/vulcanize/templates/mysql_cluster/config/rubber/deploy-mysql_cluster.rb +19 -15
  57. data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_sql/monit-mysql_cluster_sql.cnf +2 -2
  58. data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/monit-mysql_proxy.cnf +2 -2
  59. data/generators/vulcanize/templates/mysql_proxy/config/rubber/deploy-mysql_proxy.rb +3 -3
  60. data/generators/vulcanize/templates/nginx/config/rubber/deploy-nginx.rb +5 -5
  61. data/generators/vulcanize/templates/nginx/config/rubber/role/nginx/monit-nginx.conf +2 -2
  62. data/generators/vulcanize/templates/passenger/config/rubber/deploy-passenger.rb +10 -1
  63. data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger-memory.conf +1 -1
  64. data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger-sudoers.conf +2 -2
  65. data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger.conf +1 -1
  66. data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/passenger.conf +3 -3
  67. data/generators/vulcanize/templates/passenger/config/rubber/rubber-passenger.yml +2 -2
  68. data/generators/vulcanize/templates/postgresql/config/rubber/common/database.yml +12 -0
  69. data/generators/vulcanize/templates/postgresql/config/rubber/deploy-postgresql.rb +131 -0
  70. data/generators/vulcanize/templates/postgresql/config/rubber/role/db/crontab +14 -0
  71. data/generators/vulcanize/templates/postgresql/config/rubber/role/db/monit-postgresql.conf +10 -0
  72. data/generators/vulcanize/templates/postgresql/config/rubber/role/db/pg_hba.conf +89 -0
  73. data/generators/vulcanize/templates/postgresql/config/rubber/role/db/postgresql-sysctl.conf +6 -0
  74. data/generators/vulcanize/templates/postgresql/config/rubber/role/db/postgresql.conf +504 -0
  75. data/generators/vulcanize/templates/postgresql/config/rubber/rubber-postgresql.yml +45 -0
  76. data/generators/vulcanize/templates/postgresql/templates.yml +1 -0
  77. data/generators/vulcanize/templates/redis/config/rubber/deploy-redis.rb +8 -7
  78. data/generators/vulcanize/templates/resque/config/initializers/resque.rb +15 -0
  79. data/generators/vulcanize/templates/resque/config/rubber/common/resque.yml +5 -0
  80. data/generators/vulcanize/templates/resque/config/rubber/deploy-resque.rb +46 -27
  81. data/generators/vulcanize/templates/resque/config/rubber/role/resque_web/monit-resque_web.conf +14 -0
  82. data/generators/vulcanize/templates/resque/config/rubber/role/resque_worker/monit-resque_worker.conf +19 -0
  83. data/generators/vulcanize/templates/resque/config/rubber/rubber-resque.yml +14 -6
  84. data/generators/vulcanize/templates/resque/script/resque_worker_management.rb +112 -0
  85. data/generators/vulcanize/templates/resque/templates.rb +1 -0
  86. data/generators/vulcanize/templates/sphinx/config/rubber/deploy-sphinx.rb +7 -8
  87. data/generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/monit-sphinx.conf +7 -4
  88. data/generators/vulcanize/vulcanize_generator.rb +154 -49
  89. data/lib/generators/vulcanize/USAGE +6 -0
  90. data/lib/generators/vulcanize/templates/apache/config/rubber/deploy-apache.rb +51 -0
  91. data/lib/generators/vulcanize/templates/apache/config/rubber/role/apache/deflate.conf +10 -0
  92. data/lib/generators/vulcanize/templates/apache/config/rubber/role/apache/expires.conf +9 -0
  93. data/lib/generators/vulcanize/templates/apache/config/rubber/role/apache/headers.conf +6 -0
  94. data/lib/generators/vulcanize/templates/apache/config/rubber/role/apache/monit-apache.conf +8 -0
  95. data/lib/generators/vulcanize/templates/apache/config/rubber/role/apache/ports.conf +8 -0
  96. data/lib/generators/vulcanize/templates/apache/config/rubber/role/apache/setenvif.conf +52 -0
  97. data/lib/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-apache-vhost.conf +79 -0
  98. data/lib/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-apache.auth +7 -0
  99. data/lib/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-index.html +34 -0
  100. data/lib/generators/vulcanize/templates/apache/config/rubber/rubber-apache.yml +6 -0
  101. data/lib/generators/vulcanize/templates/apache/templates.yml +1 -0
  102. data/lib/generators/vulcanize/templates/base/Capfile +14 -0
  103. data/lib/generators/vulcanize/templates/base/Rakefile +21 -0
  104. data/lib/generators/vulcanize/templates/base/config/deploy.rb +55 -0
  105. data/lib/generators/vulcanize/templates/base/config/rubber/common/crontab +22 -0
  106. data/lib/generators/vulcanize/templates/base/config/rubber/common/monit-postfix.conf +8 -0
  107. data/lib/generators/vulcanize/templates/base/config/rubber/common/rubber.profile +13 -0
  108. data/lib/generators/vulcanize/templates/base/config/rubber/deploy-setup.rb +63 -0
  109. data/lib/generators/vulcanize/templates/base/config/rubber/deploy-util.rb +97 -0
  110. data/lib/generators/vulcanize/templates/base/config/rubber/rubber-dns.yml +78 -0
  111. data/lib/generators/vulcanize/templates/base/config/rubber/rubber-rvm.yml +25 -0
  112. data/lib/generators/vulcanize/templates/base/config/rubber/rubber.yml +235 -0
  113. data/lib/generators/vulcanize/templates/base/lib/tasks/rubber.rake +15 -0
  114. data/lib/generators/vulcanize/templates/base/script/cron-rake +18 -0
  115. data/lib/generators/vulcanize/templates/base/script/cron-runner +18 -0
  116. data/lib/generators/vulcanize/templates/base/script/cron-sh +67 -0
  117. data/lib/generators/vulcanize/templates/base/templates.rb +9 -0
  118. data/lib/generators/vulcanize/templates/base/templates.yml +6 -0
  119. data/lib/generators/vulcanize/templates/cassandra/config/rubber/deploy-cassandra.rb +88 -0
  120. data/lib/generators/vulcanize/templates/cassandra/config/rubber/role/cassandra/cassandra.in.sh +58 -0
  121. data/lib/generators/vulcanize/templates/cassandra/config/rubber/role/cassandra/cassandra.yaml +210 -0
  122. data/lib/generators/vulcanize/templates/cassandra/config/rubber/role/cassandra/log4j-server.properties +45 -0
  123. data/lib/generators/vulcanize/templates/cassandra/config/rubber/role/cassandra/monit-cassandra.conf +8 -0
  124. data/lib/generators/vulcanize/templates/cassandra/config/rubber/rubber-cassandra.yml +18 -0
  125. data/lib/generators/vulcanize/templates/cassandra/templates.yml +1 -0
  126. data/lib/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/role/haproxy/haproxy-mongrel.conf +23 -0
  127. data/lib/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/role/nginx/nginx-mongrel.conf +113 -0
  128. data/lib/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/rubber-complete.yml +41 -0
  129. data/lib/generators/vulcanize/templates/complete_mongrel_mysql/templates.yml +6 -0
  130. data/lib/generators/vulcanize/templates/complete_passenger/config/rubber/role/haproxy/haproxy-passenger.conf +21 -0
  131. data/lib/generators/vulcanize/templates/complete_passenger/config/rubber/rubber-complete.yml +40 -0
  132. data/lib/generators/vulcanize/templates/complete_passenger/templates.rb +9 -0
  133. data/lib/generators/vulcanize/templates/complete_passenger/templates.yml +9 -0
  134. data/lib/generators/vulcanize/templates/complete_passenger_mysql/templates.yml +4 -0
  135. data/lib/generators/vulcanize/templates/complete_passenger_postgresql/templates.yml +4 -0
  136. data/lib/generators/vulcanize/templates/cruise/config/rubber/deploy-cruise.rb +72 -0
  137. data/lib/generators/vulcanize/templates/cruise/config/rubber/role/cruise/cruise +40 -0
  138. data/lib/generators/vulcanize/templates/cruise/config/rubber/role/cruise/my.cnf +165 -0
  139. data/lib/generators/vulcanize/templates/cruise/config/rubber/role/cruise/production.rb +8 -0
  140. data/lib/generators/vulcanize/templates/cruise/config/rubber/role/cruise/site_config.rb +76 -0
  141. data/lib/generators/vulcanize/templates/cruise/config/rubber/role/web_tools/cruise-nginx.conf +11 -0
  142. data/lib/generators/vulcanize/templates/cruise/config/rubber/rubber-cruise.yml +18 -0
  143. data/lib/generators/vulcanize/templates/cruise/templates.yml +1 -0
  144. data/lib/generators/vulcanize/templates/haproxy/config/rubber/deploy-haproxy.rb +45 -0
  145. data/lib/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/haproxy-base.conf +26 -0
  146. data/lib/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/haproxy-default.conf +8 -0
  147. data/lib/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/monit-haproxy.conf +9 -0
  148. data/lib/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/syslog-haproxy.conf +11 -0
  149. data/lib/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/syslogd-default.conf +21 -0
  150. data/lib/generators/vulcanize/templates/haproxy/config/rubber/role/web_tools/haproxy-nginx.conf +10 -0
  151. data/lib/generators/vulcanize/templates/haproxy/config/rubber/rubber-haproxy.yml +7 -0
  152. data/lib/generators/vulcanize/templates/haproxy/templates.yml +1 -0
  153. data/lib/generators/vulcanize/templates/jetty/config/rubber/deploy-jetty.rb +59 -0
  154. data/lib/generators/vulcanize/templates/jetty/config/rubber/role/jetty/jetty.sh +589 -0
  155. data/lib/generators/vulcanize/templates/jetty/config/rubber/role/jetty/jetty.xml +199 -0
  156. data/lib/generators/vulcanize/templates/jetty/config/rubber/role/jetty/monit-jetty.conf +9 -0
  157. data/lib/generators/vulcanize/templates/jetty/config/rubber/rubber-jetty.yml +10 -0
  158. data/lib/generators/vulcanize/templates/jetty/templates.yml +1 -0
  159. data/lib/generators/vulcanize/templates/memcached/config/memcached.yml +28 -0
  160. data/lib/generators/vulcanize/templates/memcached/config/rubber/common/memcached.yml +14 -0
  161. data/lib/generators/vulcanize/templates/memcached/config/rubber/role/memcached/memcached.conf +52 -0
  162. data/lib/generators/vulcanize/templates/memcached/config/rubber/role/memcached/memcached_munin_plugin +249 -0
  163. data/lib/generators/vulcanize/templates/memcached/config/rubber/rubber-memcached.yml +7 -0
  164. data/lib/generators/vulcanize/templates/memcached/templates.yml +1 -0
  165. data/lib/generators/vulcanize/templates/minimal_mysql/templates.yml +7 -0
  166. data/lib/generators/vulcanize/templates/minimal_nodb/templates.yml +6 -0
  167. data/lib/generators/vulcanize/templates/mongrel/config/rubber/deploy-mongrel.rb +75 -0
  168. data/lib/generators/vulcanize/templates/mongrel/config/rubber/role/mongrel/mongrel_cluster.yml +12 -0
  169. data/lib/generators/vulcanize/templates/mongrel/config/rubber/role/mongrel/monit-mongrel.conf +20 -0
  170. data/lib/generators/vulcanize/templates/mongrel/config/rubber/rubber-mongrel.yml +9 -0
  171. data/lib/generators/vulcanize/templates/mongrel/templates.yml +1 -0
  172. data/lib/generators/vulcanize/templates/monit/config/rubber/common/monit-default.conf +15 -0
  173. data/lib/generators/vulcanize/templates/monit/config/rubber/common/monit.conf +252 -0
  174. data/lib/generators/vulcanize/templates/monit/config/rubber/deploy-monit.rb +33 -0
  175. data/lib/generators/vulcanize/templates/monit/config/rubber/role/web_tools/monit-admin-nginx.conf +10 -0
  176. data/lib/generators/vulcanize/templates/monit/config/rubber/rubber-monit.yml +6 -0
  177. data/lib/generators/vulcanize/templates/monit/templates.yml +1 -0
  178. data/lib/generators/vulcanize/templates/munin/config/rubber/common/monit-munin.conf +8 -0
  179. data/lib/generators/vulcanize/templates/munin/config/rubber/common/munin-node.conf +48 -0
  180. data/lib/generators/vulcanize/templates/munin/config/rubber/common/munin-plugins.conf +11 -0
  181. data/lib/generators/vulcanize/templates/munin/config/rubber/deploy-munin.rb +46 -0
  182. data/lib/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin-nginx.conf +8 -0
  183. data/lib/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin-plugins.conf +31 -0
  184. data/lib/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin.conf +81 -0
  185. data/lib/generators/vulcanize/templates/munin/config/rubber/rubber-munin.yml +8 -0
  186. data/lib/generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb +55 -0
  187. data/lib/generators/vulcanize/templates/munin/script/munin/example_simple.rb +24 -0
  188. data/lib/generators/vulcanize/templates/munin/templates.yml +1 -0
  189. data/lib/generators/vulcanize/templates/mysql/config/rubber/common/database.yml +12 -0
  190. data/lib/generators/vulcanize/templates/mysql/config/rubber/deploy-mysql.rb +169 -0
  191. data/lib/generators/vulcanize/templates/mysql/config/rubber/role/db/apparmor-mysql.conf +46 -0
  192. data/lib/generators/vulcanize/templates/mysql/config/rubber/role/db/crontab +14 -0
  193. data/lib/generators/vulcanize/templates/mysql/config/rubber/role/db/monit-mysql.cnf +10 -0
  194. data/lib/generators/vulcanize/templates/mysql/config/rubber/role/db/my.cnf +163 -0
  195. data/lib/generators/vulcanize/templates/mysql/config/rubber/role/mysql_slave/mysql_slave_munin_plugin +51 -0
  196. data/lib/generators/vulcanize/templates/mysql/config/rubber/rubber-mysql.yml +47 -0
  197. data/lib/generators/vulcanize/templates/mysql/templates.yml +1 -0
  198. data/lib/generators/vulcanize/templates/mysql_cluster/config/rubber/common/mysql_cluster_migrations.rb +13 -0
  199. data/lib/generators/vulcanize/templates/mysql_cluster/config/rubber/deploy-mysql_cluster.rb +177 -0
  200. data/lib/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_data/my.cnf +15 -0
  201. data/lib/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_mgm/ndb_mgmd.cnf +39 -0
  202. data/lib/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_sql/monit-mysql_cluster_sql.cnf +10 -0
  203. data/lib/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_sql/my.cnf +23 -0
  204. data/lib/generators/vulcanize/templates/mysql_cluster/config/rubber/rubber-mysql_cluster.yml +32 -0
  205. data/lib/generators/vulcanize/templates/mysql_cluster/templates.yml +1 -0
  206. data/lib/generators/vulcanize/templates/mysql_proxy/config/rubber/common/database.yml +16 -0
  207. data/lib/generators/vulcanize/templates/mysql_proxy/config/rubber/common/monit-mysql_proxy.cnf +10 -0
  208. data/lib/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy +153 -0
  209. data/lib/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy.conf +10 -0
  210. data/lib/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy.lua +5 -0
  211. data/lib/generators/vulcanize/templates/mysql_proxy/config/rubber/deploy-mysql_proxy.rb +52 -0
  212. data/lib/generators/vulcanize/templates/mysql_proxy/config/rubber/rubber-mysql_proxy.yml +11 -0
  213. data/lib/generators/vulcanize/templates/mysql_proxy/templates.yml +1 -0
  214. data/lib/generators/vulcanize/templates/nginx/config/rubber/deploy-nginx.rb +45 -0
  215. data/lib/generators/vulcanize/templates/nginx/config/rubber/role/nginx/crontab +9 -0
  216. data/lib/generators/vulcanize/templates/nginx/config/rubber/role/nginx/monit-nginx.conf +8 -0
  217. data/lib/generators/vulcanize/templates/nginx/config/rubber/role/nginx/nginx.conf +42 -0
  218. data/lib/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/nginx-tools.conf +55 -0
  219. data/lib/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/tools-index.html +30 -0
  220. data/lib/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/tools-nginx.auth +7 -0
  221. data/lib/generators/vulcanize/templates/nginx/config/rubber/rubber-nginx.yml +10 -0
  222. data/lib/generators/vulcanize/templates/nginx/templates.yml +1 -0
  223. data/lib/generators/vulcanize/templates/passenger/config/rubber/deploy-passenger.rb +46 -0
  224. data/lib/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger-memory.conf +34 -0
  225. data/lib/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger-sudoers.conf +7 -0
  226. data/lib/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger.conf +47 -0
  227. data/lib/generators/vulcanize/templates/passenger/config/rubber/role/passenger/passenger-apache-vhost.conf +46 -0
  228. data/lib/generators/vulcanize/templates/passenger/config/rubber/role/passenger/passenger.conf +35 -0
  229. data/lib/generators/vulcanize/templates/passenger/config/rubber/rubber-passenger.yml +15 -0
  230. data/lib/generators/vulcanize/templates/passenger/templates.yml +3 -0
  231. data/lib/generators/vulcanize/templates/postgresql/config/rubber/common/database.yml +12 -0
  232. data/lib/generators/vulcanize/templates/postgresql/config/rubber/deploy-postgresql.rb +131 -0
  233. data/lib/generators/vulcanize/templates/postgresql/config/rubber/role/db/crontab +14 -0
  234. data/lib/generators/vulcanize/templates/postgresql/config/rubber/role/db/monit-postgresql.conf +10 -0
  235. data/lib/generators/vulcanize/templates/postgresql/config/rubber/role/db/pg_hba.conf +89 -0
  236. data/lib/generators/vulcanize/templates/postgresql/config/rubber/role/db/postgresql-sysctl.conf +6 -0
  237. data/lib/generators/vulcanize/templates/postgresql/config/rubber/role/db/postgresql.conf +504 -0
  238. data/lib/generators/vulcanize/templates/postgresql/config/rubber/rubber-postgresql.yml +45 -0
  239. data/lib/generators/vulcanize/templates/postgresql/templates.yml +1 -0
  240. data/lib/generators/vulcanize/templates/redis/config/rubber/deploy-redis.rb +37 -0
  241. data/lib/generators/vulcanize/templates/redis/config/rubber/role/redis/crontab +8 -0
  242. data/lib/generators/vulcanize/templates/redis/config/rubber/role/redis/monit-redis.conf +9 -0
  243. data/lib/generators/vulcanize/templates/redis/config/rubber/role/redis/redis.conf +141 -0
  244. data/lib/generators/vulcanize/templates/redis/config/rubber/rubber-redis.yml +4 -0
  245. data/lib/generators/vulcanize/templates/redis/templates.yml +1 -0
  246. data/lib/generators/vulcanize/templates/resque/config/initializers/resque.rb +15 -0
  247. data/lib/generators/vulcanize/templates/resque/config/rubber/common/resque.yml +5 -0
  248. data/lib/generators/vulcanize/templates/resque/config/rubber/deploy-resque.rb +58 -0
  249. data/lib/generators/vulcanize/templates/resque/config/rubber/role/resque_web/monit-resque_web.conf +14 -0
  250. data/lib/generators/vulcanize/templates/resque/config/rubber/role/resque_worker/monit-resque_worker.conf +19 -0
  251. data/lib/generators/vulcanize/templates/resque/config/rubber/rubber-resque.yml +18 -0
  252. data/lib/generators/vulcanize/templates/resque/script/resque_worker_management.rb +112 -0
  253. data/lib/generators/vulcanize/templates/resque/templates.rb +1 -0
  254. data/lib/generators/vulcanize/templates/resque/templates.yml +3 -0
  255. data/lib/generators/vulcanize/templates/sphinx/config/rubber/common/sphinx.yml +46 -0
  256. data/lib/generators/vulcanize/templates/sphinx/config/rubber/deploy-sphinx.rb +112 -0
  257. data/lib/generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/crontab +11 -0
  258. data/lib/generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/monit-sphinx.conf +13 -0
  259. data/lib/generators/vulcanize/templates/sphinx/config/rubber/rubber-sphinx.yml +6 -0
  260. data/lib/generators/vulcanize/templates/sphinx/templates.yml +1 -0
  261. data/lib/generators/vulcanize/vulcanize_generator.rb +172 -0
  262. data/lib/rubber.rb +42 -6
  263. data/lib/rubber/cloud/aws.rb +4 -0
  264. data/lib/rubber/dns/zerigo.rb +9 -3
  265. data/lib/rubber/environment.rb +1 -1
  266. data/lib/rubber/generator.rb +8 -8
  267. data/lib/rubber/instance.rb +1 -1
  268. data/lib/rubber/railtie.rb +14 -0
  269. data/lib/rubber/recipes/rubber.rb +6 -0
  270. data/lib/rubber/recipes/rubber/deploy.rb +3 -3
  271. data/lib/rubber/recipes/rubber/setup.rb +22 -17
  272. data/lib/rubber/recipes/rubber/utils.rb +37 -14
  273. data/lib/rubber/util.rb +36 -1
  274. data/rails/init.rb +1 -4
  275. metadata +244 -35
  276. data/generators/vulcanize/templates/resque/config/rubber/deploy-resque-worker-default.rb +0 -38
  277. data/generators/vulcanize/templates/resque/config/rubber/role/resque_worker_default/monit-resque_worker_default.conf +0 -19
@@ -0,0 +1,45 @@
1
+
2
+ # REQUIRED: The credentials for creating/accessong your app's database
3
+ #
4
+ db_user: "#{app_name[0,16]}"
5
+ db_pass:
6
+ db_name: "#{app_name}_#{RUBBER_ENV}"
7
+
8
+ db_slave_user: "#{('slave_' + db_user)[0,16]}"
9
+ db_replicator_user: "#{('replicator_' + db_user)[0,16]}"
10
+
11
+ # REQUIRED: The command to use to do a full backup of your database using
12
+ # "rake rubber:backup_db"
13
+ db_backup_cmd: "nice sudo -u postgres pg_dumpall -U postgres | gzip -c > %backup_file%"
14
+
15
+ # REQUIRED: The command to use to restore the database using
16
+ # "rake rubber:restore_db_s3"
17
+ # This command will receive the data generated by db_backup_cmd via
18
+ # its standard input
19
+ db_restore_cmd: "zcat - | psql -Uroot -h %host% %name%"
20
+
21
+ postgresql_ver: 8.4
22
+ postgresql_conf_dir: "/etc/postgresql/#{postgresql_ver}/main"
23
+ postgresql_data_dir: /mnt/postgresql/data
24
+ postgresql_archive_dir: /mnt/postgresql/archive
25
+ postgresql_pid_file: "/var/run/postgresql/#{postgresql_ver}-main.pid"
26
+ postgresql_ctl: "/usr/sbin/service postgresql-#{postgresql_ver}"
27
+
28
+ # Capistrano needs db:primary role for migrate to work,
29
+ # so we might as well just make consistent across the board
30
+ role_dependencies:
31
+ postgresql_master: [db:primary=true]
32
+ postgresql_slave: [db]
33
+ db:primary=true: [postgresql_master]
34
+ db: [postgresql_slave]
35
+
36
+ packages: [postgresql-client, libpq-dev]
37
+ gems: [pg]
38
+
39
+ roles:
40
+ postgresql_master:
41
+ db_server_id: 1
42
+ postgresql_slave:
43
+ db_server_id: 2
44
+ db:
45
+ packages: [postgresql]
@@ -0,0 +1 @@
1
+ description: The PostgreSQL database system
@@ -1,4 +1,3 @@
1
-
2
1
  namespace :rubber do
3
2
 
4
3
  namespace :redis do
@@ -8,27 +7,29 @@ namespace :rubber do
8
7
  after "rubber:install_packages", "rubber:redis:custom_install"
9
8
 
10
9
  task :custom_install, :roles => :redis do
11
- custom_package('http://ftp.us.debian.org/debian/pool/main/r/redis/', 'redis-server', '1.2.5-1', '! -x /usr/bin/redis-server')
10
+ custom_package('http://ftp.us.debian.org/debian/pool/main/r/redis/', 'redis-server', '1.2.6-1', '! -x /usr/bin/redis-server')
11
+ # force redis config regen so db dir gets recreated when creating staging from a bundle
12
+ rsudo "rm -f /etc/redis/redis.conf"
12
13
  end
13
14
 
14
15
  desc "Stops the redis server"
15
- task :stop, :roles => :redis, :on_error => :continue do
16
- sudo "/etc/init.d/redis-server stop"
16
+ task :stop, :roles => :redis do
17
+ rsudo "/etc/init.d/redis-server stop; exit 0"
17
18
  end
18
19
 
19
20
  desc "Starts the redis server"
20
21
  task :start, :roles => :redis do
21
- sudo "/etc/init.d/redis-server start"
22
+ rsudo "/etc/init.d/redis-server start"
22
23
  end
23
24
 
24
25
  desc "Restarts the redis server"
25
26
  task :restart, :roles => :redis do
26
- sudo "/etc/init.d/redis-server restart"
27
+ rsudo "/etc/init.d/redis-server restart"
27
28
  end
28
29
 
29
30
  desc "Reloads the redis server"
30
31
  task :reload, :roles => :redis do
31
- sudo "/etc/init.d/redis-server restart"
32
+ rsudo "/etc/init.d/redis-server restart"
32
33
  end
33
34
 
34
35
  end
@@ -0,0 +1,15 @@
1
+ require 'yaml'
2
+ require 'resque'
3
+
4
+ rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
5
+ rails_env = ENV['RAILS_ENV'] || 'development'
6
+
7
+ redis_host = 'localhost:6379'
8
+
9
+ resque_yml = rails_root + '/config/resque.yml'
10
+ if File.exist? resque_yml
11
+ resque_config = YAML.load_file(resque_yml)
12
+ redis_host = resque_config[rails_env]
13
+ end
14
+
15
+ Resque.redis = redis_host
@@ -0,0 +1,5 @@
1
+ <%
2
+ @path = "#{RUBBER_ROOT}/config/resque.yml"
3
+ %>
4
+
5
+ <%= RUBBER_ENV %>: <%= rubber_instances.for_role('redis').first.full_name rescue 'localhost' %>:6379
@@ -4,36 +4,55 @@ namespace :rubber do
4
4
  namespace :resque do
5
5
 
6
6
  rubber.allow_optional_tasks(self)
7
-
8
- after "rubber:install_packages", "rubber:resque:custom_install"
9
-
10
- task :custom_install, :roles => :resque do
11
- rubber.sudo_script 'install_resque', <<-ENDSCRIPT
12
- if [ -d resque ]; then
13
- rm -r resque
14
- fi
15
-
16
- git clone git://github.com/defunkt/resque.git
17
-
18
- if [ -d #{rubber_env.resque_web_dir} ]; then
19
- rm -r #{rubber_env.resque_web_dir}
20
- fi
21
-
22
- mkdir -p #{rubber_env.resque_web_dir}
23
- mkdir #{rubber_env.resque_web_dir}/tmp
24
- mv resque/config.ru #{rubber_env.resque_web_dir}
25
- mv resque/lib/resque/server/* #{rubber_env.resque_web_dir}/
26
-
27
- rm -f /var/www/resque
28
- ln -s #{rubber_env.resque_web_dir}/public /var/www/resque
29
- ENDSCRIPT
7
+
8
+ namespace :worker do
9
+
10
+ rubber.allow_optional_tasks(self)
11
+
12
+ before "deploy:stop", "rubber:resque:worker:stop"
13
+ after "deploy:start", "rubber:resque:worker:start"
14
+ after "deploy:restart", "rubber:resque:worker:restart"
15
+
16
+ desc "Starts resque workers"
17
+ task :start, :roles => :resque_worker do
18
+ rsudo "cd #{current_path} && RUBBER_ENV=#{rails_env} ./script/resque_worker_management.rb start", :as => rubber_env.app_user
19
+ end
20
+
21
+ desc "Stops resque workers"
22
+ task :stop, :roles => :resque_worker do
23
+ rsudo "cd #{current_path} && RUBBER_ENV=#{rails_env} ./script/resque_worker_management.rb stop", :as => rubber_env.app_user
24
+ end
25
+
26
+ desc "Restarts resque workers"
27
+ task :restart, :roles => :resque_worker do
28
+ rsudo "cd #{current_path} && RUBBER_ENV=#{rails_env} ./script/resque_worker_management.rb restart", :as => rubber_env.app_user
29
+ end
30
30
  end
31
31
 
32
- after "rubber:setup_app_permissions", "rubber:resque:setup_resque_permissions"
32
+ namespace :web do
33
+ rubber.allow_optional_tasks(self)
34
+
35
+ before "deploy:stop", "rubber:resque:web:stop"
36
+ after "deploy:start", "rubber:resque:web:start"
37
+ after "deploy:restart", "rubber:resque:web:restart"
38
+
39
+ desc "Starts resque web tools"
40
+ task :start, :roles => :resque_web do
41
+ rsudo "RAILS_ENV=#{RUBBER_ENV} resque-web --pid-file /var/run/resque_web.pid --port #{rubber_env.resque_web_port} --no-launch #{current_path}/config/initializers/resque.rb"
42
+ end
43
+
44
+ desc "Stops resque web tools"
45
+ task :stop, :roles => :resque_web do
46
+ rsudo "RAILS_ENV=#{RUBBER_ENV} resque-web --pid-file /var/run/resque_web.pid --kill"
47
+ end
48
+
49
+ desc "Restarts resque web tools"
50
+ task :restart, :roles => :resque_web do
51
+ rubber.resque.web.stop
52
+ rubber.resque.web.start
53
+ end
33
54
 
34
- task :setup_resque_permissions, :roles => :resque do
35
- sudo "chown -R #{rubber_env.app_user}:#{rubber_env.app_user} #{rubber_env.resque_web_dir}/config.ru"
36
55
  end
37
-
56
+
38
57
  end
39
58
  end
@@ -0,0 +1,14 @@
1
+ <%
2
+ @path = '/etc/monit/monit.d/monit-resque_web.conf'
3
+
4
+ PIDFILE = "/var/run/resque_web.pid"
5
+ start_program = "HOME=/root resque-web --pid-file #{PIDFILE} --port #{rubber_env.resque_web_port} --no-launch #{RUBBER_ROOT}/config/initializers/resque.rb"
6
+ stop_program = "HOME=/root resque-web --pid-file #{PIDFILE} --kill"
7
+ %>
8
+
9
+ check process resque_web with pidfile <%= PIDFILE %>
10
+ group resque_web
11
+ start program = "bash -l -c '<%= start_program %>'"
12
+ stop program = "bash -l -c '<%= stop_program %>'"
13
+
14
+ if totalmem > 350.0 MB for 15 cycles then restart
@@ -0,0 +1,19 @@
1
+ <%
2
+ @path = '/etc/monit/monit.d/monit-resque_worker.conf'
3
+ %>
4
+
5
+ <% rubber_env.resque_workers.each_with_index do |worker, i| %>
6
+ <%
7
+ PIDFILE = "#{RUBBER_ROOT}/tmp/pids/resque_worker_#{i}.pid"
8
+
9
+ start_program = "cd #{RUBBER_ROOT} && ./script/resque_worker_management.rb start #{i}"
10
+ stop_program = "cd #{RUBBER_ROOT} && ./script/resque_worker_management.rb stop #{i}"
11
+ %>
12
+
13
+ check process resque_worker_<%= i %> with pidfile <%= PIDFILE %>
14
+ group resque_worker
15
+ start program = "/usr/bin/sudo -H -u <%= rubber_env.app_user %> bash -l -c '<%= start_program %>'"
16
+ stop program = "/usr/bin/sudo -H -u <%= rubber_env.app_user %> bash -l -c '<%= stop_program %>'"
17
+
18
+ if totalmem > 350.0 MB for 15 cycles then restart
19
+ <% end %>
@@ -1,10 +1,18 @@
1
- resque_web_dir: /opt/resque
1
+ resque_web_port: 5678
2
2
 
3
- resque_worker_default_count: 5
3
+ # list of workers with the queues to be run on each - on each worker instance,
4
+ # a worker is run for each item in this list to handle the queues specified
5
+ #
6
+ resque_workers:
7
+ -
8
+ queues: *
9
+ poll_interval: 1
10
+ -
11
+ queues: *
12
+ poll_interval: 1
13
+
14
+ gems: [yajl-ruby resque]
4
15
 
5
16
  role_dependencies:
6
- css_validator: [redis]
17
+ web_tools: [resque_web]
7
18
 
8
- roles:
9
- resque:
10
- gems: [redis redis-namespace yajl-ruby sinatra resque]
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ env = ENV["RUBBER_ENV"] ||= "development"
4
+ root = File.join(File.dirname(__FILE__), '..')
5
+ rails_env_file = File.join(root, 'config', 'environment.rb')
6
+
7
+ if File.exists? rails_env_file
8
+ require(rails_env_file)
9
+ else
10
+ require "rubber"
11
+ Rubber::initialize(root, env)
12
+ require 'resque'
13
+ require "#{root}/config/initializers/resque.rb"
14
+ end
15
+
16
+ def start_all(workers)
17
+ puts "Starting all workers"
18
+ workers.each_with_index do |worker, i|
19
+ start(worker, i)
20
+ end
21
+ end
22
+
23
+ def start(worker, index)
24
+ puts "Starting worker #{index}/#{worker.queues}"
25
+
26
+ log_file = log_file(index)
27
+ pid_file = pid_file(index)
28
+
29
+ queues = worker.queues.to_s.split(',')
30
+
31
+ daemonize(log_file, pid_file) do
32
+ resque_worker = Resque::Worker.new(*queues)
33
+ resque_worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
34
+ resque_worker.very_verbose = ENV['VVERBOSE']
35
+
36
+ puts "*** Starting worker #{resque_worker}"
37
+ resque_worker.work(worker.poll_interval.to_i || 5) # interval, will block
38
+ end
39
+ end
40
+
41
+ def stop_all(workers)
42
+ puts "Stopping all workers"
43
+ workers.size.times do |i|
44
+ stop(i)
45
+ end
46
+ end
47
+
48
+ def stop(index)
49
+ puts "Stopping worker #{index}"
50
+
51
+ pid_file = pid_file(index)
52
+ pid = File.read(pid_file).to_i rescue nil
53
+ if pid
54
+ puts "Killing worker #{index}: pid #{pid}"
55
+ begin
56
+ Process.kill("QUIT", pid)
57
+ rescue Exception => e
58
+ puts e
59
+ end
60
+ File.delete(pid_file) if File.exist?(pid_file)
61
+ else
62
+ puts "No pid file for worker #{index}: #{pid_file}"
63
+ end
64
+ end
65
+
66
+ def daemonize(log_file, pid_file)
67
+ return if fork
68
+ Process::setsid
69
+ exit!(0) if fork
70
+ Dir::chdir("/")
71
+ File.umask 0000
72
+ FileUtils.touch log_file
73
+ STDIN.reopen log_file
74
+ STDOUT.reopen log_file, "a"
75
+ STDERR.reopen log_file, "a"
76
+
77
+ File.open(pid_file, 'w') {|f| f.write("#{Process.pid}") }
78
+
79
+ yield if block_given?
80
+ exit(0)
81
+ end
82
+
83
+ def pid_file(index)
84
+ File.expand_path "#{Rubber.root}/tmp/pids/resque_worker_#{index}.pid"
85
+ end
86
+
87
+ def log_file(index)
88
+ File.expand_path "#{Rubber.root}/log/resque_worker_#{index}.log"
89
+ end
90
+
91
+ action = ARGV[0]
92
+ worker_index = ARGV[1] ? ARGV[1].to_i : nil
93
+ if action.nil? || ! %w[start stop restart].include?(action)
94
+ puts "Usage: script/resque_worker_management.rb [start|stop|restart]"
95
+ end
96
+
97
+ workers = Rubber.config.resque_workers
98
+
99
+ case action
100
+ when 'start'
101
+ worker_index ? start(workers[worker_index], worker_index) : start_all(workers)
102
+ when 'stop'
103
+ worker_index ? stop(worker_index) : stop_all(workers)
104
+ when 'restart'
105
+ if worker_index
106
+ stop(worker_index)
107
+ start(workers[worker_index], worker_index)
108
+ else
109
+ stop_all(workers)
110
+ start_all(workers)
111
+ end
112
+ end
@@ -0,0 +1 @@
1
+ gem "resque" if Rubber::Util::is_bundler?
@@ -60,26 +60,25 @@ namespace :rubber do
60
60
  desc "Do sphinx setup tasks"
61
61
  task :setup, :roles => :sphinx do
62
62
  # Setup links to sphinx config/index as they need to persist between deploys
63
- sudo "mkdir -p #{sphinx_root} #{sphinx_root}/config #{sphinx_root}/db"
64
- sudo "chown -R #{runner}:#{runner} #{sphinx_root}"
63
+ rsudo "mkdir -p #{sphinx_root} #{sphinx_root}/config #{sphinx_root}/db"
64
+ rsudo "chown -R #{runner}:#{runner} #{sphinx_root}"
65
65
  end
66
66
 
67
67
  desc "Setup paths for sphinx runtime"
68
68
  task :config_dir, :roles => :sphinx do
69
- sudo "rm -rf #{current_path}/sphinx"
70
- sudo "ln -sf #{sphinx_root} #{current_path}/sphinx"
69
+ rsudo "rm -rf #{current_path}/sphinx"
70
+ rsudo "ln -sf #{sphinx_root} #{current_path}/sphinx"
71
71
  end
72
72
 
73
73
  # runs the given ultrasphinx rake tasks
74
74
  def run_sphinx task
75
- cmd = "sh -c 'cd #{current_path} && sudo -u #{runner} RAILS_ENV=#{RUBBER_ENV} rake #{task}'"
76
- sudo cmd
75
+ rsudo "cd #{current_path} && RAILS_ENV=#{RUBBER_ENV} rake #{task}", :as => runner
77
76
  end
78
77
 
79
78
 
80
79
  desc "Stops sphinx searchd"
81
- task :stop, :roles => :sphinx, :on_error => :continue do
82
- run_sphinx 'ts:stop'
80
+ task :stop, :roles => :sphinx do
81
+ run_sphinx 'ts:stop; exit 0'
83
82
  end
84
83
 
85
84
  desc "Starts sphinx searchd"
@@ -1,10 +1,13 @@
1
1
  <%
2
2
  @path = '/etc/monit/monit.d/monit-sphinx.conf'
3
+
4
+ PIDFILE = "#{RUBBER_ROOT}/log/searchd.#{RUBBER_ENV}.pid"
5
+ start_program = "cd #{RUBBER_ROOT} && rake ts:start"
6
+ stop_program = "cd #{RUBBER_ROOT} && rake ts:stop"
3
7
  %>
4
8
 
5
- check process sphinx with pidfile <%= RUBBER_ROOT %>/log/searchd.<%= RUBBER_ENV %>.pid
9
+ check process sphinx with pidfile <%= PIDFILE %>
6
10
  group sphinx-<%= RUBBER_ENV %>
7
- start program = "/usr/bin/sudo -u rails sh -c 'cd <%= RUBBER_ROOT %> && PATH=<%= rubber_env.ruby_prefix %>/bin:/usr/local/bin:$PATH RAILS_ENV=<%= RUBBER_ENV %> rake ts:start'"
8
- stop program = "/usr/bin/sudo -u rails sh -c 'cd <%= RUBBER_ROOT %> && PATH=<%= rubber_env.ruby_prefix %>/bin:/usr/local/bin:$PATH RAILS_ENV=<%= RUBBER_ENV %> rake ts:stop'"
11
+ start program = "/usr/bin/sudo -H -u <%= rubber_env.app_user %> bash -l -c '<%= start_program %>'"
12
+ stop program = "/usr/bin/sudo -H -u <%= rubber_env.app_user %> bash -l -c '<%= stop_program %>'"
9
13
  if failed host <%= rubber_env.host %> port 3312 with timeout 5 seconds for 5 cycles then restart
10
-
@@ -1,67 +1,172 @@
1
- require 'fileutils'
2
1
  require 'find'
2
+ require 'yaml'
3
3
 
4
- class VulcanizeGenerator < Rails::Generator::NamedBase
5
-
6
- TEMPLATE_ROOT = File.dirname(__FILE__) + "/templates"
7
- TEMPLATE_FILE = "templates.yml"
8
-
9
- def manifest
10
- record do |m|
11
- templates = [file_name] + actions
12
- templates.each do |t|
13
- apply_template(m, t)
4
+ if Rubber::Util::is_rails2?
5
+ require 'fileutils'
6
+ require 'commands/generate'
7
+
8
+ class VulcanizeGenerator < Rails::Generator::NamedBase
9
+ include Rails::Generator::Commands
10
+
11
+ TEMPLATE_ROOT = File.dirname(__FILE__) + "/templates" unless defined?(TEMPLATE_ROOT)
12
+ TEMPLATE_FILE = "templates.yml" unless defined?(TEMPLATE_FILE)
13
+
14
+ def manifest
15
+ record do |m|
16
+ templates = [file_name] + actions
17
+ templates.each do |t|
18
+ apply_template(m, t)
19
+ end
14
20
  end
15
21
  end
22
+
23
+ def apply_template(m, name)
24
+ sp = source_path("#{name}/")
25
+ unless File.directory?(sp)
26
+ raise Rails::Generator::UsageError.new("Invalid template #{name}, use one of #{valid_templates.join(', ')}")
27
+ end
28
+
29
+ templ_conf = load_template_config(sp)
30
+ deps = templ_conf['dependent_templates'] || []
31
+ deps.each do |dep|
32
+ apply_template(m, dep)
33
+ end
34
+
35
+ extra_generator_steps_file = File.join(TEMPLATE_ROOT, name, 'templates.rb')
36
+
37
+ Find.find(sp) do |f|
38
+ Find.prune if File.basename(f) =~ /^(CVS|\.svn)$/
39
+ Find.prune if f == "#{sp}#{TEMPLATE_FILE}"
40
+ Find.prune if f == extra_generator_steps_file # don't copy over templates.rb
41
+
42
+ rel = f.gsub(/#{source_root}\//, '')
43
+ dest_rel = rel.gsub(/^#{name}\//, '')
44
+
45
+ # Only include optional files when their conditions eval to true
46
+ template_conf = YAML.load(File.read(TEMPLATE_FILE)) rescue {}
47
+ optional = template_conf['optional'][dest_rel] rescue nil
48
+ Find.prune if optional && ! eval(optional)
49
+
50
+ m.directory(dest_rel) if File.directory?(f)
51
+ if File.file?(f)
52
+ # force scripts to be executable
53
+ opts = (File.read(f) =~ /^#!/) ? {:chmod => 0755} : {}
54
+ m.file(rel, dest_rel, opts)
55
+ end
56
+ end
57
+
58
+ puts extra_generator_steps_file
59
+ if File.exist? extra_generator_steps_file
60
+ eval File.read(extra_generator_steps_file), binding, extra_generator_steps_file
61
+ end
62
+ end
63
+
64
+ protected
65
+ def valid_templates
66
+ valid = Dir.entries(TEMPLATE_ROOT).delete_if {|e| e =~ /(^\.)|svn|CVS/ }
67
+ end
68
+
69
+ def load_template_config(template_dir)
70
+ templ_file = "#{template_dir}/templates.yml"
71
+ templ_conf = YAML.load(File.read(templ_file)) rescue {}
72
+ return templ_conf
73
+ end
74
+
75
+ def banner
76
+ usage = "Usage: #{$0} vulcanize template_name ...\n"
77
+ usage << "where template_name is one of:\n\n"
78
+ valid_templates.each do |t|
79
+ templ_conf = load_template_config("#{TEMPLATE_ROOT}/#{t}")
80
+ desc = templ_conf['description']
81
+ usage << " #{t}: #{desc}\n"
82
+ end
83
+ return usage
84
+ end
16
85
  end
17
86
 
18
- def apply_template(m, name)
19
- sp = source_path("#{name}/")
20
- unless File.directory?(sp)
21
- raise Rails::Generator::UsageError.new("Invalid template #{name}, use one of #{valid_templates.join(', ')}")
87
+ else
88
+ require 'rails/generators'
89
+
90
+ class VulcanizeGenerator < Rails::Generators::NamedBase
91
+
92
+ def self.source_root
93
+ File.join(File.dirname(__FILE__), 'templates')
94
+ end
95
+
96
+ def copy_template_files
97
+ @template_dependencies = find_dependencies(file_name)
98
+ ([file_name] + @template_dependencies).each do |template|
99
+ apply_template(template)
100
+ end
22
101
  end
23
-
24
- templ_conf = load_template_config(sp)
25
- deps = templ_conf['dependent_templates'] || []
26
- deps.each do |dep|
27
- apply_template(m, dep)
102
+
103
+ protected
104
+
105
+ # helper to test for rails for optional templates
106
+ def rails?
107
+ Rubber::Util::is_rails?
28
108
  end
29
-
30
- Find.find(sp) do |f|
31
- Find.prune if File.basename(f) =~ /^(CVS|\.svn)$/
32
- Find.prune if f == "#{sp}#{TEMPLATE_FILE}"
33
-
34
- rel = f.gsub(/#{source_root}\//, '')
35
- dest_rel = rel.gsub(/^#{name}\//, '')
36
- m.directory(dest_rel) if File.directory?(f)
37
- if File.file?(f)
38
- # force scripts to be executable
39
- opts = (File.read(f) =~ /^#!/) ? {:chmod => 0755} : {}
40
- m.file(rel, dest_rel, opts)
109
+
110
+ def find_dependencies(name)
111
+ template_dir = File.join(self.class.source_root, name, '')
112
+ unless File.directory?(template_dir)
113
+ raise Rails::Generators::Error.new("Invalid template #{name}, use one of #{valid_templates.join(', ')}")
41
114
  end
42
115
 
116
+ template_conf = load_template_config(template_dir)
117
+ template_dependencies = template_conf['dependent_templates'] || []
118
+
119
+ template_dependencies.clone.each do |dep|
120
+ template_dependencies.concat(find_dependencies(dep))
121
+ end
122
+
123
+ return template_dependencies.uniq
124
+ end
125
+
126
+ def apply_template(name)
127
+ template_dir = File.join(self.class.source_root, name, '')
128
+ unless File.directory?(template_dir)
129
+ raise Rails::Generators::Error.new("Invalid template #{name}, use one of #{valid_templates.join(', ')}")
130
+ end
131
+
132
+ template_conf = load_template_config(template_dir)
133
+
134
+ extra_generator_steps_file = File.join(template_dir, 'templates.rb')
135
+
136
+ Find.find(template_dir) do |f|
137
+ Find.prune if f == File.join(template_dir, 'templates.yml') # don't copy over templates.yml
138
+ Find.prune if f == extra_generator_steps_file # don't copy over templates.rb
139
+
140
+ template_rel = f.gsub(/#{template_dir}/, '')
141
+ source_rel = f.gsub(/#{self.class.source_root}\//, '')
142
+ dest_rel = source_rel.gsub(/^#{name}\//, '')
143
+
144
+ # Only include optional files when their conditions eval to true
145
+ optional = template_conf['optional'][template_rel] rescue nil
146
+ Find.prune if optional && ! eval(optional)
147
+
148
+ if File.directory?(f)
149
+ empty_directory(dest_rel)
150
+ else
151
+ copy_file(source_rel, dest_rel)
152
+ src_mode = File.stat(f).mode
153
+ dest_mode = File.stat(File.join(destination_root, dest_rel)).mode
154
+ chmod(dest_rel, src_mode) if src_mode != dest_mode
155
+ end
156
+ end
157
+
158
+ if File.exist? extra_generator_steps_file
159
+ eval File.read(extra_generator_steps_file), binding, extra_generator_steps_file
160
+ end
43
161
  end
44
- end
45
162
 
46
- protected
47
163
  def valid_templates
48
- valid = Dir.entries(TEMPLATE_ROOT).delete_if {|e| e =~ /(^\.)|svn|CVS/ }
164
+ valid = Dir.entries(self.class.source_root).delete_if {|e| e =~ /(^\.)|svn|CVS/ }
49
165
  end
50
-
166
+
51
167
  def load_template_config(template_dir)
52
- templ_file = "#{template_dir}/templates.yml"
53
- templ_conf = YAML.load(File.read(templ_file)) rescue {}
54
- return templ_conf
168
+ YAML.load(File.read(File.join(template_dir, 'templates.yml'))) rescue {}
55
169
  end
170
+ end
56
171
 
57
- def banner
58
- usage = "Usage: #{$0} vulcanize template_name ...\n"
59
- usage << "where template_name is one of:\n\n"
60
- valid_templates.each do |t|
61
- templ_conf = load_template_config("#{TEMPLATE_ROOT}/#{t}")
62
- desc = templ_conf['description']
63
- usage << " #{t}: #{desc}\n"
64
- end
65
- return usage
66
- end
67
172
  end