le1t0-deprec 2.1.6.001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. data/CHANGELOG +444 -0
  2. data/COPYING +19 -0
  3. data/LICENSE +339 -0
  4. data/README +154 -0
  5. data/THANKS +17 -0
  6. data/bin/depify +139 -0
  7. data/docs/EXAMPLE-installing_tracks.txt +41 -0
  8. data/docs/README.nagios +22 -0
  9. data/docs/README.rails +17 -0
  10. data/docs/config_gen_explained.txt +39 -0
  11. data/docs/deprec-1.x/deprec-1.x.quickstart +50 -0
  12. data/docs/deprec-1.x/notes.txt +12 -0
  13. data/docs/old/deprec_banner.gif +0 -0
  14. data/docs/windows_linux.txt +350 -0
  15. data/docs/xen/traffic_monitoring_with_vnstat.txt +95 -0
  16. data/docs/xen/xen-tools-notes.txt +31 -0
  17. data/docs/xen/xen_on_hardy.txt +39 -0
  18. data/lib/deprec.rb +42 -0
  19. data/lib/deprec/capistrano_extensions.rb +446 -0
  20. data/lib/deprec/recipes.rb +7 -0
  21. data/lib/deprec/recipes/aoe.rb +79 -0
  22. data/lib/deprec/recipes/app/mongrel.rb +213 -0
  23. data/lib/deprec/recipes/app/passenger.rb +190 -0
  24. data/lib/deprec/recipes/ar_sendmail.rb +67 -0
  25. data/lib/deprec/recipes/aspell.rb +22 -0
  26. data/lib/deprec/recipes/canonical.rb +68 -0
  27. data/lib/deprec/recipes/cap.rb +39 -0
  28. data/lib/deprec/recipes/chef.rb +68 -0
  29. data/lib/deprec/recipes/collectd.rb +112 -0
  30. data/lib/deprec/recipes/db/couchdb.rb +107 -0
  31. data/lib/deprec/recipes/db/mysql.rb +194 -0
  32. data/lib/deprec/recipes/db/postgresql.rb +104 -0
  33. data/lib/deprec/recipes/db/sqlite.rb +37 -0
  34. data/lib/deprec/recipes/ddclient.rb +51 -0
  35. data/lib/deprec/recipes/deprec.rb +167 -0
  36. data/lib/deprec/recipes/deprecated.rb +71 -0
  37. data/lib/deprec/recipes/drbd.rb +137 -0
  38. data/lib/deprec/recipes/dummy.rb +22 -0
  39. data/lib/deprec/recipes/example.rb +115 -0
  40. data/lib/deprec/recipes/git.rb +97 -0
  41. data/lib/deprec/recipes/gitosis.rb.disabled +55 -0
  42. data/lib/deprec/recipes/glusterfs.rb +176 -0
  43. data/lib/deprec/recipes/god.rb +70 -0
  44. data/lib/deprec/recipes/haproxy.rb +115 -0
  45. data/lib/deprec/recipes/heartbeat.rb +138 -0
  46. data/lib/deprec/recipes/imagemagick/imagemagick_bin.rb +24 -0
  47. data/lib/deprec/recipes/imagemagick/imagemagick_src.rb +39 -0
  48. data/lib/deprec/recipes/integrity.rb +108 -0
  49. data/lib/deprec/recipes/iptables.rb +94 -0
  50. data/lib/deprec/recipes/java.rb +23 -0
  51. data/lib/deprec/recipes/keepalived.rb +78 -0
  52. data/lib/deprec/recipes/ldap.rb +52 -0
  53. data/lib/deprec/recipes/logrotate.rb +56 -0
  54. data/lib/deprec/recipes/lvm.rb +20 -0
  55. data/lib/deprec/recipes/memcache.rb +49 -0
  56. data/lib/deprec/recipes/mongodb.rb +94 -0
  57. data/lib/deprec/recipes/monit.rb +135 -0
  58. data/lib/deprec/recipes/mysql_proxy.rb +67 -0
  59. data/lib/deprec/recipes/nagios.rb +361 -0
  60. data/lib/deprec/recipes/network.rb +116 -0
  61. data/lib/deprec/recipes/ntp.rb +103 -0
  62. data/lib/deprec/recipes/php.rb +58 -0
  63. data/lib/deprec/recipes/postfix.rb +115 -0
  64. data/lib/deprec/recipes/profiles.rb +125 -0
  65. data/lib/deprec/recipes/raid/amcc_3ware.rb +21 -0
  66. data/lib/deprec/recipes/rails.rb +330 -0
  67. data/lib/deprec/recipes/redhat_cluster.rb +228 -0
  68. data/lib/deprec/recipes/redis.rb +90 -0
  69. data/lib/deprec/recipes/ruby/mri.rb +55 -0
  70. data/lib/deprec/recipes/ruby/ree.rb +40 -0
  71. data/lib/deprec/recipes/rvm.rb +32 -0
  72. data/lib/deprec/recipes/s3utils.rb +63 -0
  73. data/lib/deprec/recipes/sphinx/thinking_sphinx.rb +105 -0
  74. data/lib/deprec/recipes/sphinx/ultrasphinx.rb +86 -0
  75. data/lib/deprec/recipes/ssh.rb +147 -0
  76. data/lib/deprec/recipes/ssl.rb +56 -0
  77. data/lib/deprec/recipes/starling.rb +119 -0
  78. data/lib/deprec/recipes/svn.rb +171 -0
  79. data/lib/deprec/recipes/syslog.rb +63 -0
  80. data/lib/deprec/recipes/trac.rb.disabled +277 -0
  81. data/lib/deprec/recipes/tsung.rb +74 -0
  82. data/lib/deprec/recipes/ubuntu.rb +90 -0
  83. data/lib/deprec/recipes/users.rb +90 -0
  84. data/lib/deprec/recipes/utils.rb +58 -0
  85. data/lib/deprec/recipes/vnstat.rb +85 -0
  86. data/lib/deprec/recipes/web/apache.rb +143 -0
  87. data/lib/deprec/recipes/web/nginx.rb +172 -0
  88. data/lib/deprec/recipes/wordpress.rb.notworking +96 -0
  89. data/lib/deprec/recipes/wpmu.rb +103 -0
  90. data/lib/deprec/recipes/xen.rb +364 -0
  91. data/lib/deprec/recipes/xentools.rb +101 -0
  92. data/lib/deprec/recipes_minus_rails.rb +125 -0
  93. data/lib/deprec/templates/aoe/aoe-init +55 -0
  94. data/lib/deprec/templates/aoe/fence_aoemask +351 -0
  95. data/lib/deprec/templates/apache/namevirtualhosts.conf +5 -0
  96. data/lib/deprec/templates/apache/ports.conf.erb +5 -0
  97. data/lib/deprec/templates/apache/status.conf.erb +17 -0
  98. data/lib/deprec/templates/ar_sendmail/logrotate.conf.erb +9 -0
  99. data/lib/deprec/templates/ar_sendmail/monit.conf.erb +5 -0
  100. data/lib/deprec/templates/chef/chef.json.erb +1 -0
  101. data/lib/deprec/templates/chef/solo.rb +2 -0
  102. data/lib/deprec/templates/collectd/collectd-init.d +153 -0
  103. data/lib/deprec/templates/collectd/collectd.conf.erb +686 -0
  104. data/lib/deprec/templates/ddclient/ddclient.conf.erb +11 -0
  105. data/lib/deprec/templates/ddclient/ddclient.erb +15 -0
  106. data/lib/deprec/templates/deprec/caprc.erb +14 -0
  107. data/lib/deprec/templates/drbd/drbd.conf.erb +531 -0
  108. data/lib/deprec/templates/glusterfs/glusterfsd-init.erb +95 -0
  109. data/lib/deprec/templates/gnbd_client/cluster.conf.erb +21 -0
  110. data/lib/deprec/templates/gnbd_client/clvm-default.erb +3 -0
  111. data/lib/deprec/templates/gnbd_client/cman-default.erb +6 -0
  112. data/lib/deprec/templates/gnbd_client/gnbdimports.conf.erb +1 -0
  113. data/lib/deprec/templates/gnbd_server/cluster.conf.erb +20 -0
  114. data/lib/deprec/templates/gnbd_server/clvm-default.erb +3 -0
  115. data/lib/deprec/templates/gnbd_server/cman-default.erb +6 -0
  116. data/lib/deprec/templates/gnbd_server/gnbd-server-default.erb +1 -0
  117. data/lib/deprec/templates/gnbd_server/gnbdexports.conf.erb +1 -0
  118. data/lib/deprec/templates/god/god-conf.erb +2 -0
  119. data/lib/deprec/templates/god/god-init.erb +47 -0
  120. data/lib/deprec/templates/haproxy/haproxy-init.d +120 -0
  121. data/lib/deprec/templates/haproxy/haproxy.cfg.erb +31 -0
  122. data/lib/deprec/templates/heartbeat/authkeys.erb +2 -0
  123. data/lib/deprec/templates/heartbeat/ha.cf.erb +15 -0
  124. data/lib/deprec/templates/heartbeat/haresources.erb +1 -0
  125. data/lib/deprec/templates/integrity/apache_vhost.erb +4 -0
  126. data/lib/deprec/templates/integrity/config.ru.erb +21 -0
  127. data/lib/deprec/templates/integrity/config.yml.erb +43 -0
  128. data/lib/deprec/templates/iptables/firewall-default.erb +13 -0
  129. data/lib/deprec/templates/iptables/firewall-init.erb +171 -0
  130. data/lib/deprec/templates/keepalived/keepalived.conf.erb +18 -0
  131. data/lib/deprec/templates/logrotate/logrotate.conf.erb +32 -0
  132. data/lib/deprec/templates/mongodb/mongodb-init.d +88 -0
  133. data/lib/deprec/templates/mongrel/apache_vhost.conf.erb +148 -0
  134. data/lib/deprec/templates/mongrel/logrotate.conf.erb +11 -0
  135. data/lib/deprec/templates/mongrel/mongrel_cluster-init-script +54 -0
  136. data/lib/deprec/templates/mongrel/mongrel_cluster.yml.erb +10 -0
  137. data/lib/deprec/templates/mongrel/monit.conf.erb +17 -0
  138. data/lib/deprec/templates/mongrel/nginx_vhost.conf.erb +41 -0
  139. data/lib/deprec/templates/monit/monit-init-script +104 -0
  140. data/lib/deprec/templates/monit/monitrc.erb +250 -0
  141. data/lib/deprec/templates/monit/nothing.monitrc +0 -0
  142. data/lib/deprec/templates/mysql/create_databases.sql +20 -0
  143. data/lib/deprec/templates/mysql/database.yml.prod +6 -0
  144. data/lib/deprec/templates/mysql/database.yml.stage +6 -0
  145. data/lib/deprec/templates/mysql/my.cnf.erb +140 -0
  146. data/lib/deprec/templates/mysql/sphinx.conf.prod +542 -0
  147. data/lib/deprec/templates/mysql/sphinx.conf.stage +542 -0
  148. data/lib/deprec/templates/mysql_proxy/mysql-proxy-default.erb +4 -0
  149. data/lib/deprec/templates/nagios/README +32 -0
  150. data/lib/deprec/templates/nagios/cgi.cfg.erb +357 -0
  151. data/lib/deprec/templates/nagios/check_linux_free_memory.pl +118 -0
  152. data/lib/deprec/templates/nagios/check_mongrel_cluster.rb +82 -0
  153. data/lib/deprec/templates/nagios/htpasswd.users +1 -0
  154. data/lib/deprec/templates/nagios/mrtg.cfg +180 -0
  155. data/lib/deprec/templates/nagios/nagios.cfg.erb +1325 -0
  156. data/lib/deprec/templates/nagios/nrpe.cfg.erb +222 -0
  157. data/lib/deprec/templates/nagios/nrpe.xinetd.erb +16 -0
  158. data/lib/deprec/templates/nagios/objects/commands.cfg.erb +265 -0
  159. data/lib/deprec/templates/nagios/objects/contacts.cfg.erb +89 -0
  160. data/lib/deprec/templates/nagios/objects/hosts.cfg.erb +114 -0
  161. data/lib/deprec/templates/nagios/objects/localhost.cfg.erb +116 -0
  162. data/lib/deprec/templates/nagios/objects/services.cfg.erb +165 -0
  163. data/lib/deprec/templates/nagios/objects/timeperiods.cfg.erb +94 -0
  164. data/lib/deprec/templates/nagios/resource.cfg.erb +34 -0
  165. data/lib/deprec/templates/network/hostname.erb +1 -0
  166. data/lib/deprec/templates/network/hosts.erb +2 -0
  167. data/lib/deprec/templates/network/interfaces.erb +18 -0
  168. data/lib/deprec/templates/network/resolv.conf.erb +6 -0
  169. data/lib/deprec/templates/nginx/logrotate.conf.erb +13 -0
  170. data/lib/deprec/templates/nginx/mime.types.erb +70 -0
  171. data/lib/deprec/templates/nginx/nginx-init-script +62 -0
  172. data/lib/deprec/templates/nginx/nginx.conf.erb +125 -0
  173. data/lib/deprec/templates/nginx/nginx.logrotate.d +12 -0
  174. data/lib/deprec/templates/nginx/nothing.conf +1 -0
  175. data/lib/deprec/templates/nginx/rails_nginx_vhost.conf.erb +41 -0
  176. data/lib/deprec/templates/ntp/ntp.conf.erb +42 -0
  177. data/lib/deprec/templates/passenger/apache_vhost.erb +29 -0
  178. data/lib/deprec/templates/passenger/logrotate.conf.erb +12 -0
  179. data/lib/deprec/templates/passenger/passenger.conf.erb +21 -0
  180. data/lib/deprec/templates/passenger/passenger.load.erb +3 -0
  181. data/lib/deprec/templates/postfix/aliases.erb +3 -0
  182. data/lib/deprec/templates/postfix/dynamicmaps.cf.erb +8 -0
  183. data/lib/deprec/templates/postfix/main.cf.erb +36 -0
  184. data/lib/deprec/templates/postfix/master.cf.erb +77 -0
  185. data/lib/deprec/templates/redis/redis-conf.erb +132 -0
  186. data/lib/deprec/templates/redis/redis-init.erb +50 -0
  187. data/lib/deprec/templates/s3utils/s3cfg +35 -0
  188. data/lib/deprec/templates/s3utils/s3config.yml +3 -0
  189. data/lib/deprec/templates/sphinx/monit.conf.erb +5 -0
  190. data/lib/deprec/templates/ssh/ssh_config.erb +50 -0
  191. data/lib/deprec/templates/ssh/sshd_config.erb +78 -0
  192. data/lib/deprec/templates/ssl/make-ssl-cert +138 -0
  193. data/lib/deprec/templates/ssl/ssl-cert-snakeoil.key +15 -0
  194. data/lib/deprec/templates/ssl/ssl-cert-snakeoil.pem +19 -0
  195. data/lib/deprec/templates/starling/monit.conf.erb +14 -0
  196. data/lib/deprec/templates/starling/starling-init-script.erb +71 -0
  197. data/lib/deprec/templates/subversion/svn.apache.vhost.erb +43 -0
  198. data/lib/deprec/templates/syslog/syslog.conf.erb +71 -0
  199. data/lib/deprec/templates/syslog/syslogd.erb +13 -0
  200. data/lib/deprec/templates/trac/apache_vhost.conf.erb +24 -0
  201. data/lib/deprec/templates/trac/nginx_vhost.conf.erb +26 -0
  202. data/lib/deprec/templates/trac/trac.ini.erb +169 -0
  203. data/lib/deprec/templates/trac/trac_deprec.png +0 -0
  204. data/lib/deprec/templates/trac/tracd-init.erb +43 -0
  205. data/lib/deprec/templates/trac/users.htdigest.erb +0 -0
  206. data/lib/deprec/templates/tsung/tsung.xml.erb +47 -0
  207. data/lib/deprec/templates/vnstat/config.php +57 -0
  208. data/lib/deprec/templates/wordpress/apache2_wordpress_vhost.conf.erb +31 -0
  209. data/lib/deprec/templates/wordpress/wp-config.php.erb +31 -0
  210. data/lib/deprec/templates/wpmu/apache_vhost.conf.erb +13 -0
  211. data/lib/deprec/templates/xen/network-bridge-wrapper +3 -0
  212. data/lib/deprec/templates/xen/xend-config.sxp.erb +195 -0
  213. data/lib/deprec/templates/xen/xend-init.erb +57 -0
  214. data/lib/deprec/templates/xen/xendomains.erb +137 -0
  215. data/lib/deprec/templates/xentools/100-ubuntu-setup +26 -0
  216. data/lib/deprec/templates/xentools/15-disable-hwclock +40 -0
  217. data/lib/deprec/templates/xentools/30-disable-gettys +57 -0
  218. data/lib/deprec/templates/xentools/31-ubuntu-setup +32 -0
  219. data/lib/deprec/templates/xentools/40-setup-networking +145 -0
  220. data/lib/deprec/templates/xentools/98-custom +17 -0
  221. data/lib/deprec/templates/xentools/xen-tools.conf.erb +278 -0
  222. data/lib/deprec/templates/xentools/xm.tmpl.erb +138 -0
  223. data/lib/deprec_cmd_completion.sh +26 -0
  224. data/lib/deprec_minus_rails.rb +12 -0
  225. data/lib/vmbuilder_plugins/all.rb +20 -0
  226. data/lib/vmbuilder_plugins/apt.rb +93 -0
  227. data/lib/vmbuilder_plugins/emerge.rb +76 -0
  228. data/lib/vmbuilder_plugins/gem.rb +100 -0
  229. data/lib/vmbuilder_plugins/std.rb +203 -0
  230. metadata +304 -0
@@ -0,0 +1,21 @@
1
+ # Copyright 2009-2010 by le1t0@github. All rights reserved.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :deprec do
4
+ namespace :amcc_3ware do
5
+
6
+ desc "Install 3ware management tools"
7
+ task :install, :roles => :storage_backend do
8
+ sudo "sh -c 'cd /tmp ; wget http://www.3ware.com/download/Escalade9690SA-Series/9.5.3/tw_cli-linux-x86_64-9.5.3.tgz'"
9
+ sudo "sh -c 'cd /tmp ; wget http://www.3ware.com/download/Escalade9690SA-Series/9.5.3/tw_cli-linux-x86-9.5.3.tgz'"
10
+
11
+ sudo "sh -c 'cd /opt ; mkdir -p 3ware_tools/x86_64 ; cd 3ware_tools/x86_64 ; tar zxf /tmp/tw_cli-linux-x86_64-9.5.3.tgz'"
12
+ sudo "sh -c 'cd /opt ; mkdir -p 3ware_tools/i686 ; cd 3ware_tools/i686 ; tar zxf /tmp/tw_cli-linux-x86-9.5.3.tgz ; ln -sf /opt/3ware_tools/i686 /opt/3ware_tools/i386'"
13
+ sudo "ln -sf /opt/3ware_tools/$(uname -m) /opt/3ware"
14
+
15
+ sudo "chmod 755 /opt/3ware/tw_cli"
16
+ sudo "ln -sf /opt/3ware/tw_cli /usr/local/bin/"
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,330 @@
1
+ # Copyright 2006-2010 by Mike Bailey, le1t0@github. All rights reserved.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+
4
+ set :app_user_prefix, 'app_'
5
+ set(:app_user) { app_user_prefix + application }
6
+ set :app_group_prefix, 'app_'
7
+ set(:app_group) { app_group_prefix + application }
8
+ set(:app_user_homedir) { deploy_to }
9
+ set :database_yml_in_scm, true
10
+ set :app_symlinks, nil
11
+ set :rails_env, 'production'
12
+ set :gems_for_project, nil # Array of gems to be installed for app
13
+ set :packages_for_project, nil # Array of packages to be installed for app
14
+ set :shared_dirs, nil # Array of directories that should be created under shared/
15
+ # and linked to in the project
16
+
17
+ # Hook into the default capistrano deploy tasks
18
+ before 'deploy:setup', :except => { :no_release => true } do
19
+ top.deprec.rails.setup_user_perms
20
+ top.deprec.rails.create_app_user_and_group
21
+ top.deprec.rails.setup_paths
22
+ top.deprec.rails.setup_shared_dirs
23
+ top.deprec.rails.install_packages_for_project
24
+ top.deprec.rails.install_gems_for_project
25
+ end
26
+
27
+ after 'deploy:setup', :except => { :no_release => true } do
28
+ top.deprec.rails.create_config_dir
29
+ top.deprec.rails.config_gen
30
+ top.deprec.rails.config
31
+ top.deprec.rails.activate_services
32
+ top.deprec.rails.set_perms_on_shared_and_releases
33
+ top.deprec.web.reload if web_server_type.to_s != 'none'
34
+ top.deprec.rails.setup_database
35
+ end
36
+
37
+ after 'deploy:symlink', :roles => :app do
38
+ top.deprec.rails.symlink_shared_dirs
39
+ top.deprec.rails.symlink_database_yml unless database_yml_in_scm
40
+ top.deprec.rails.make_writable_by_app
41
+ top.deprec.passenger.set_owner_of_environment_rb if app_server_type.to_s == 'passenger'
42
+ end
43
+
44
+ after :deploy, "deploy:cleanup"
45
+
46
+ namespace :rake do
47
+ namespace :gems do
48
+ task :install, :roles => :app do
49
+ run "cd #{current_path} && #{sudo} rake gems:install"
50
+ end
51
+ end
52
+ end
53
+ namespace :db do
54
+ task :migrate, :roles => :db do
55
+ run "cd #{current_path} && #{sudo} rake gems:install"
56
+ end
57
+ end
58
+
59
+ namespace :deprec do
60
+ namespace :rails do
61
+
62
+ #
63
+ # If database.yml is not kept in scm and it is present in local
64
+ # config dir then push it out to server.
65
+ #
66
+ before 'deprec:rails:symlink_database_yml', :roles => :app do
67
+ push_database_yml unless database_yml_in_scm
68
+ end
69
+
70
+ task :setup_database, :roles => :db do
71
+ if ! roles[:db].servers.empty? # Some apps don't use database!
72
+ deprec2.read_database_yml
73
+ top.deprec.db.create_user
74
+ top.deprec.db.create_database
75
+ top.deprec.db.grant_user_access_to_database
76
+ end
77
+ end
78
+
79
+ task :install, :roles => :app do
80
+ install_deps
81
+ install_gems
82
+ end
83
+
84
+ task :install_deps do
85
+ apt.install( {:base => %w(libmysqlclient15-dev sqlite3 libsqlite3-ruby libsqlite3-dev libpq-dev)}, :stable )
86
+ end
87
+
88
+ # install some required ruby gems
89
+ task :install_gems do
90
+ gem2.install 'sqlite3-ruby'
91
+ gem2.install 'mysql'
92
+ gem2.install 'ruby-pg'
93
+ gem2.install 'rails'
94
+ gem2.install 'rake'
95
+ gem2.install 'rspec'
96
+ end
97
+
98
+ desc <<-DESC
99
+ Install full rails stack on a stock standard ubuntu server (7.10, 8.04)
100
+ DESC
101
+ task :install_stack do
102
+
103
+ top.deprec.ruby.install
104
+ top.deprec.rails.install
105
+ top.deprec.svn.install
106
+ top.deprec.git.install
107
+ top.deprec.web.install # Uses value of web_server_type
108
+ top.deprec.app.install # Uses value of app_server_type
109
+ top.deprec.monit.install if use_monit # FIXME: should be generic namespace monitoring, with :none option
110
+ top.deprec.logrotate.install if use_logrotate # FIXME: should be generic namespace logrotation, with :none option
111
+
112
+ # We not longer install database server as part of this task.
113
+ # There is too much danger that someone will wreck an existing
114
+ # shared database.
115
+ #
116
+ # Install database server with:
117
+ #
118
+ # cap deprec:db:install
119
+ end
120
+
121
+ task :install_rails_stack do
122
+ puts "deprecated: this task is now called install_stack"
123
+ install_stack
124
+ end
125
+
126
+ desc "Generate config files for rails app."
127
+ task :config_gen do
128
+ top.deprec.web.config_gen_project if web_server_type.to_s != 'none'
129
+ top.deprec.app.config_gen_project if app_server_type.to_s != 'none'
130
+ end
131
+
132
+ desc "Push out config files for rails app."
133
+ task :config do
134
+ top.deprec.web.config_project if web_server_type.to_s != 'none'
135
+ top.deprec.app.config_project if app_server_type.to_s != 'none'
136
+ end
137
+
138
+ task :create_config_dir, :roles => :app do
139
+ deprec2.mkdir("#{shared_path}/config", :group => group, :mode => 0775, :via => :sudo)
140
+ end
141
+
142
+ # XXX This should be restricted a bit to limit what app can write to. - Mike
143
+ desc "set group ownership and permissions on dirs app server needs to write to"
144
+ task :make_writable_by_app, :roles => :app do
145
+ dirs = "#{shared_path} #{current_path}/tmp #{current_path}/public"
146
+ sudo "chgrp -R #{app_group} #{dirs}"
147
+ sudo "chmod -R g+w #{dirs}"
148
+
149
+ # set owner and group of log files
150
+ # XXX Factor out mongrel
151
+ files = ["#{mongrel_log_dir}/mongrel.log", "#{mongrel_log_dir}/#{rails_env}.log"]
152
+ files.each { |file|
153
+ sudo "touch #{file}"
154
+ sudo "chown #{app_user} #{file}"
155
+ sudo "chgrp #{app_group} #{file}"
156
+ sudo "chmod g+w #{file}"
157
+ }
158
+ end
159
+
160
+ desc "Create deployment group and add current user to it"
161
+ task :setup_user_perms, :roles => [:app, :web] do
162
+ deprec2.groupadd(group)
163
+ deprec2.add_user_to_group(user, group)
164
+ deprec2.groupadd(app_group)
165
+ deprec2.add_user_to_group(user, app_group)
166
+ # we've just added ourself to a group - need to teardown connection
167
+ # so that next command uses new session where we belong in group
168
+ deprec2.teardown_connections
169
+ end
170
+
171
+ desc "Create user and group for application to run as"
172
+ task :create_app_user_and_group, :roles => :app do
173
+ deprec2.groupadd(app_group)
174
+ deprec2.useradd(app_user, :group => app_group, :homedir => false)
175
+ # Set the primary group for the user the application runs as (in case
176
+ # user already existed when previous command was run)
177
+ sudo "usermod --gid #{app_group} --home #{app_user_homedir} #{app_user}"
178
+ end
179
+
180
+ task :set_perms_on_shared_and_releases, :roles => :app do
181
+ releases = File.join(deploy_to, 'releases')
182
+ sudo "chgrp -R #{group} #{shared_path} #{releases}"
183
+ sudo "chmod -R g+w #{shared_path} #{releases}"
184
+ end
185
+
186
+ # Setup database server.
187
+ task :setup_db, :roles => :db, :only => { :primary => true } do
188
+ top.deprec.mysql.setup if db_server_type.to_s == 'mysql' # FIXME: should be generic db namespace call?
189
+ end
190
+
191
+ # setup extra paths required for deployment
192
+ task :setup_paths, :roles => [:app, :web] do
193
+ deprec2.mkdir(deploy_to, :mode => 0775, :group => group, :via => :sudo)
194
+ deprec2.mkdir(shared_path, :mode => 0775, :group => group, :via => :sudo)
195
+ end
196
+
197
+ # Symlink list of files and dirs from shared to current
198
+ #
199
+ # XXX write up explanation
200
+ #
201
+ desc "Setup shared dirs"
202
+ task :setup_shared_dirs, :roles => [:app, :web] do
203
+ if shared_dirs
204
+ shared_dirs.each { |dir| deprec2.mkdir( "#{shared_path}/#{dir}", :via => :sudo ) }
205
+ end
206
+ end
207
+ #
208
+ desc "Symlink shared dirs."
209
+ task :symlink_shared_dirs, :roles => [:app, :web] do
210
+ if shared_dirs
211
+ shared_dirs.each do |dir|
212
+ path = File.split(dir)[0]
213
+ if path != '.'
214
+ deprec2.mkdir("#{current_path}/#{path}")
215
+ end
216
+ sudo "test -d #{current_path}/#{dir} && mv #{current_path}/#{dir} #{current_path}/#{dir}.moved_by_deprec; exit 0"
217
+ run "ln -nfs #{shared_path}/#{dir} #{current_path}/#{dir}"
218
+ end
219
+ end
220
+ end
221
+
222
+ task :install_packages_for_project, :roles => :app do
223
+ if packages_for_project
224
+ apt.install({ :base => packages_for_project }, :stable)
225
+ end
226
+ end
227
+
228
+ task :install_gems_for_project, :roles => :app do
229
+ if gems_for_project
230
+ gems_for_project.each { |gem| gem2.install(gem) }
231
+ end
232
+ end
233
+
234
+ desc "Activate web, app and monit"
235
+ task :activate_services do
236
+ top.deprec.web.activate if web_server_type.to_s != 'none'
237
+ top.deprec.app.activate if app_server_type.to_s != 'none'
238
+ top.deprec.monit.activate if use_monit # FIXME: should be generic namespace monitoring, with :none option
239
+ end
240
+
241
+ # database.yml stuff
242
+ #
243
+ # XXX DRY this up
244
+ # I don't know how to let :gen_db_yml check if values have been set.
245
+ #
246
+ # if (self.respond_to?("db_host_#{rails_env}".to_sym)) # doesn't seem to work
247
+
248
+ set :db_host_default, lambda { Capistrano::CLI.prompt 'Enter database host', 'localhost'}
249
+ set :db_host_staging, lambda { db_host_default }
250
+ set :db_host_production, lambda { db_host_default }
251
+
252
+ set :db_name_default, lambda { Capistrano::CLI.prompt 'Enter database name', "#{application}_#{rails_env}" }
253
+ set :db_name_staging, lambda { db_name_default }
254
+ set :db_name_production, lambda { db_name_default }
255
+
256
+ set :db_user_default, lambda { Capistrano::CLI.prompt 'Enter database user', 'root' }
257
+ set :db_user_staging, lambda { db_user_default }
258
+ set :db_user_production, lambda { db_user_default }
259
+
260
+ set :db_pass_default, lambda { Capistrano::CLI.prompt 'Enter database pass', '' }
261
+ set :db_pass_staging, lambda { db_pass_default }
262
+ set :db_pass_production, lambda { db_pass_default }
263
+
264
+ set :db_adaptor_default, lambda { Capistrano::CLI.prompt 'Enter database adaptor', 'mysql' }
265
+ set :db_adaptor_staging, lambda { db_adaptor_default }
266
+ set :db_adaptor_production, lambda { db_adaptor_default }
267
+
268
+ set :db_socket_default, lambda { Capistrano::CLI.prompt('Enter database socket', '')}
269
+ set :db_socket_staging, lambda { db_socket_default }
270
+ set :db_socket_production, lambda { db_socket_default }
271
+
272
+ task :generate_database_yml, :roles => :app do
273
+ database_configuration = render :template => <<-EOF
274
+ #{rails_env}:
275
+ adapter: #{self.send("db_adaptor_#{rails_env}")}
276
+ database: #{self.send("db_name_#{rails_env}")}
277
+ username: #{self.send("db_user_#{rails_env}")}
278
+ password: #{self.send("db_pass_#{rails_env}")}
279
+ host: #{self.send("db_host_#{rails_env}")}
280
+ socket: #{self.send("db_socket_#{rails_env}")}
281
+ EOF
282
+ run "mkdir -p #{deploy_to}/#{shared_dir}/config"
283
+ put database_configuration, "#{deploy_to}/#{shared_dir}/config/database.yml"
284
+ end
285
+
286
+ desc "Link in the production database.yml"
287
+ task :symlink_database_yml, :roles => :app do
288
+ run "#{sudo} ln -nfs #{shared_path}/config/database.yml #{current_path}/config/database.yml"
289
+ end
290
+
291
+ desc "Copy database.yml to shared/config/database.yml. Useful if not kept in scm"
292
+ task :push_database_yml, :roles => :app do
293
+ stage = exists?(:stage) ? fetch(:stage).to_s : ''
294
+ full_local_path = File.join('config', stage, 'database.yml')
295
+ if File.exists?(full_local_path)
296
+ std.su_put(File.read(full_local_path), "#{shared_path}/config/database.yml", '/tmp/')
297
+ end
298
+ end
299
+
300
+ end
301
+
302
+ namespace :database do
303
+
304
+ desc "Create database"
305
+ task :create, :roles => :app do
306
+ run "cd #{deploy_to}/current && rake db:create RAILS_ENV=#{rails_env}"
307
+ end
308
+
309
+ desc "Run database migrations"
310
+ task :migrate, :roles => :app do
311
+ run "cd #{deploy_to}/current && rake db:migrate RAILS_ENV=#{rails_env}"
312
+ end
313
+
314
+ desc "Run database migrations"
315
+ task :schema_load, :roles => :app do
316
+ run "cd #{deploy_to}/current && rake db:schema:load RAILS_ENV=#{rails_env}"
317
+ end
318
+
319
+ desc "Roll database back to previous migration"
320
+ task :rollback, :roles => :app do
321
+ run "cd #{deploy_to}/current && rake db:rollback RAILS_ENV=#{rails_env}"
322
+ end
323
+
324
+ end
325
+
326
+ end
327
+
328
+ end
329
+
330
+
@@ -0,0 +1,228 @@
1
+ # Copyright 2009-2010 by le1t0@github. All rights reserved.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :deprec do
4
+ namespace :redhat_cluster do
5
+
6
+ set :redhat_cluster_name, 'storagecluster'
7
+ set :redhat_cluster_config_version, '1'
8
+ set :redhat_cluster_nodes, [
9
+ { :name => 'clusternode1' },
10
+ { :name => 'clusternode2' },
11
+ { :name => 'clusternode3' },
12
+ { :name => 'clusternode4' },
13
+ { :name => 'clusternode5' }
14
+ ]
15
+ set :redhat_cluster_fence_methods, [
16
+ { :name => 'human', :device_name => 'last_resort', :options => { :agent => 'fence_manual' } }
17
+ ]
18
+
19
+ set :redhat_cluster_exported_devices, [
20
+ {
21
+ :device => '/dev/sdb1', :export_name => 'assets', :gnbd_clients => '4'
22
+ }
23
+ ]
24
+
25
+ desc "Install redhat_cluster on server (daemon)"
26
+ task :install_server, :roles => :storage_server do
27
+ install_deps_server
28
+ config_server
29
+ activate_server
30
+ end
31
+
32
+ desc "Install redhat_cluster on server (client)"
33
+ task :install_client, :roles => :storage_client do
34
+ install_deps_client
35
+ config_client
36
+ activate_client
37
+ end
38
+
39
+ task :install_deps_common, :roles => [:storage_client, :storage_server] do
40
+ apt.install( {:base => %w(gfs-tools gfs2-tools cman clvm)}, :stable )
41
+ end
42
+
43
+ task :install_deps_server, :roles => :storage_server do
44
+ install_deps_common
45
+ apt.install( {:base => %w(gnbd-server)}, :stable )
46
+ end
47
+
48
+ task :install_deps_client, :roles => :storage_client do
49
+ install_deps_common
50
+ apt.install( {:base => %w(gnbd-client)}, :stable )
51
+ end
52
+
53
+ desc "format devices on gnbd_server"
54
+ task :format_devices, :roles => :storage_server do
55
+ redhat_cluster_exported_devices.each do |dev|
56
+ sudo "gfs_mkfs -p lock_dlm -t #{redhat_cluster_name}:#{dev[:export_name]} -j #{dev[:gnbd_clients]} #{dev[:device]}"
57
+ end
58
+ end
59
+
60
+ SYSTEM_CONFIG_FILES[:gnbd_client] = [
61
+ {:template => 'clvm-default.erb',
62
+ :path => '/etc/default/clvm',
63
+ :mode => 0644,
64
+ :owner => 'root:root'},
65
+ {:template => 'cman-default.erb',
66
+ :path => '/etc/default/cman',
67
+ :mode => 0644,
68
+ :owner => 'root:root'},
69
+ {:template => 'gnbdimports.conf.erb',
70
+ :path => '/etc/cluster/gnbdimports.conf',
71
+ :mode => 0644,
72
+ :owner => 'root:root'},
73
+ {:template => 'cluster.conf.erb',
74
+ :path => '/etc/cluster/cluster.conf',
75
+ :mode => 0644,
76
+ :owner => 'root:root'}
77
+ ]
78
+
79
+ SYSTEM_CONFIG_FILES[:gnbd_server] = [
80
+ {:template => 'clvm-default.erb',
81
+ :path => '/etc/default/clvm',
82
+ :mode => 0644,
83
+ :owner => 'root:root'},
84
+ {:template => 'cman-default.erb',
85
+ :path => '/etc/default/cman',
86
+ :mode => 0644,
87
+ :owner => 'root:root'},
88
+ {:template => 'gnbd-server-default.erb',
89
+ :path => '/etc/default/gnbd-server',
90
+ :mode => 0644,
91
+ :owner => 'root:root'},
92
+ {:template => 'gnbdexports.conf.erb',
93
+ :path => '/etc/cluster/gnbdexports.conf',
94
+ :mode => 0644,
95
+ :owner => 'root:root'},
96
+ {:template => 'cluster.conf.erb',
97
+ :path => '/etc/cluster/cluster.conf',
98
+ :mode => 0644,
99
+ :owner => 'root:root'}
100
+ ]
101
+
102
+ desc "Generate config files for redhat_cluster (daemon)"
103
+ task :config_gen_server do
104
+ SYSTEM_CONFIG_FILES[:gnbd_server].each do |file|
105
+ deprec2.render_template(:gnbd_server, file)
106
+ end
107
+ end
108
+
109
+ desc "Generate config files for redhat_cluster (client)"
110
+ task :config_gen_client do
111
+ SYSTEM_CONFIG_FILES[:gnbd_client].each do |file|
112
+ deprec2.render_template(:gnbd_client, file)
113
+ end
114
+ end
115
+
116
+ task :config_common, :roles => [:storage_client, :storage_server] do
117
+ deprec2.append_to_file_if_missing('/etc/modules', 'dm-mod')
118
+ deprec2.append_to_file_if_missing('/etc/modules', 'gfs')
119
+ deprec2.append_to_file_if_missing('/etc/modules', 'lock_dlm')
120
+ deprec2.append_to_file_if_missing('/etc/modules', 'gnbd')
121
+ deprec2.substitute_in_file('/etc/lvm/lvm.conf', '^(\s*)(locking_type = 1\s*)$', '$1#$2')
122
+ deprec2.substitute_in_file('/etc/lvm/lvm.conf', '^(\s*)#\s*(locking_library = \"liblvm2clusterlock.so\"\s*)$', '$1$2')
123
+ deprec2.substitute_in_file('/etc/lvm/lvm.conf', '^(\s*)#\s*(locking_type = 2\s*)$', '$1$2')
124
+ deprec2.substitute_in_file('/etc/lvm/lvm.conf', '^(\s*)#\s*(library_dir = \"/lib/lvm2\"\s*)$', '$1$2', '%')
125
+ end
126
+
127
+ desc "Push redhat_cluster config files to server (daemon)"
128
+ task :config_server, :roles => :storage_server do
129
+ deprec2.push_configs(:gnbd_server, SYSTEM_CONFIG_FILES[:gnbd_server])
130
+ config_common
131
+ reactivate_server
132
+ end
133
+
134
+ desc "Push redhat_cluster config files to server (client)"
135
+ task :config_client, :roles => :storage_client do
136
+ deprec2.push_configs(:gnbd_client, SYSTEM_CONFIG_FILES[:gnbd_client])
137
+ config_common
138
+ reactivate_client
139
+ end
140
+
141
+ task :start_server, :roles => :storage_server do
142
+ sudo "/etc/init.d/cman start"
143
+ sudo "/etc/init.d/gnbd-server start"
144
+ sudo "/etc/init.d/clvm start"
145
+ sudo "/etc/init.d/gfs-tools start"
146
+ sudo "/etc/init.d/gfs2-tools start"
147
+ end
148
+
149
+ task :start_client, :roles => :storage_client do
150
+ sudo "/etc/init.d/cman start"
151
+ sudo "/etc/init.d/clvm start"
152
+ sudo "/etc/init.d/gfs-tools start"
153
+ sudo "/etc/init.d/gfs2-tools start"
154
+ sudo "/etc/init.d/gnbd-client start"
155
+ end
156
+
157
+ task :stop_server, :roles => :storage_server do
158
+ sudo "/etc/init.d/gfs-tools stop"
159
+ sudo "/etc/init.d/gfs2-tools stop"
160
+ sudo "/etc/init.d/clvm stop"
161
+ sudo "/etc/init.d/gnbd-server stop"
162
+ sudo "/etc/init.d/cman stop"
163
+ end
164
+
165
+ task :stop_client, :roles => :storage_client do
166
+ sudo "/etc/init.d/gfs-tools stop"
167
+ sudo "/etc/init.d/gfs2-tools stop"
168
+ sudo "/etc/init.d/gnbd-client stop"
169
+ sudo "/etc/init.d/clvm stop"
170
+ sudo "/etc/init.d/cman stop"
171
+ end
172
+
173
+ task :restart_server do
174
+ stop_server
175
+ start_server
176
+ end
177
+
178
+ task :restart_client do
179
+ stop_client
180
+ start_client
181
+ end
182
+
183
+ task :activate_common, :roles => [:storage_client, :storage_server] do
184
+ sudo "update-rc.d clvm start 65 S . stop 3 0 6 ."
185
+ sudo "update-rc.d cman start 61 S . stop 5 0 6 ."
186
+ sudo "update-rc.d gfs-tools start 65 S . stop 2 0 6 ."
187
+ sudo "update-rc.d gfs2-tools start 65 S . stop 2 0 6 ."
188
+ end
189
+
190
+ task :activate_server, :roles => :storage_server do
191
+ sudo "update-rc.d gnbd-server start 63 S . stop 3 0 6 ."
192
+ activate_common
193
+ end
194
+
195
+ task :activate_client, :roles => :storage_client do
196
+ sudo "update-rc.d gnbd-client start 65 S . stop 2 0 6 ."
197
+ activate_common
198
+ end
199
+
200
+ task :deactivate_common, :roles => [:storage_client, :storage_server] do
201
+ sudo "update-rc.d -f clvm remove"
202
+ sudo "update-rc.d -f cman remove"
203
+ sudo "update-rc.d -f gfs-tools remove"
204
+ sudo "update-rc.d -f gfs2-tools remove"
205
+ end
206
+
207
+ task :deactivate_server, :roles => :storage_server do
208
+ sudo "update-rc.d -f gnbd-server remove"
209
+ deactivate_common
210
+ end
211
+
212
+ task :deactivate_client, :roles => :storage_client do
213
+ sudo "update-rc.d -f gnbd-client remove"
214
+ deactivate_common
215
+ end
216
+
217
+ task :reactivate_server do
218
+ deactivate_server
219
+ activate_server
220
+ end
221
+
222
+ task :reactivate_client do
223
+ deactivate_client
224
+ activate_client
225
+ end
226
+ end
227
+ end
228
+ end