deprec 1.9.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/CHANGELOG +280 -0
  2. data/COPYING +19 -0
  3. data/LICENSE +339 -0
  4. data/README +152 -0
  5. data/THANKS +17 -0
  6. data/bin/depify +128 -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/{README.quickstart → deprec-1.x/deprec-1.x.quickstart} +4 -1
  12. data/docs/{building_edge_capistrano.txt → deprec-1.x/notes.txt} +6 -3
  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 +8 -1
  19. data/lib/deprec/capistrano_extensions.rb +442 -0
  20. data/lib/deprec/recipes.rb +50 -233
  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 +197 -0
  24. data/lib/deprec/recipes/apt_mirror.rb +99 -0
  25. data/lib/deprec/recipes/ar_sendmail.rb +67 -0
  26. data/lib/deprec/recipes/canonical.rb +68 -0
  27. data/lib/deprec/recipes/db/mysql.rb +144 -0
  28. data/lib/deprec/recipes/db/postgresql.rb +104 -0
  29. data/lib/deprec/recipes/db/sqlite.rb +37 -0
  30. data/lib/deprec/recipes/ddclient.rb +51 -0
  31. data/lib/deprec/recipes/deprec.rb +199 -0
  32. data/lib/deprec/recipes/deprecated.rb +71 -0
  33. data/lib/deprec/recipes/example.rb +115 -0
  34. data/lib/deprec/recipes/git.rb +97 -0
  35. data/lib/deprec/recipes/gitosis.rb +48 -0
  36. data/lib/deprec/recipes/heartbeat.rb +138 -0
  37. data/lib/deprec/recipes/logrotate.rb +54 -0
  38. data/lib/deprec/recipes/lvm.rb +20 -0
  39. data/lib/deprec/recipes/memcache.rb +6 -2
  40. data/lib/deprec/recipes/monit.rb +143 -0
  41. data/lib/deprec/recipes/nagios.rb +305 -0
  42. data/lib/deprec/recipes/network.rb +93 -0
  43. data/lib/deprec/recipes/ntp.rb +103 -0
  44. data/lib/deprec/recipes/php.rb +58 -0
  45. data/lib/deprec/recipes/postfix.rb +115 -0
  46. data/lib/deprec/recipes/rails.rb +300 -55
  47. data/lib/deprec/recipes/ruby/mri.rb +55 -0
  48. data/lib/deprec/recipes/ruby/ree.rb +41 -0
  49. data/lib/deprec/recipes/sphinx.rb +86 -0
  50. data/lib/deprec/recipes/ssh.rb +85 -18
  51. data/lib/deprec/recipes/ssl.rb +55 -0
  52. data/lib/deprec/recipes/starling.rb +119 -0
  53. data/lib/deprec/recipes/svn.rb +163 -183
  54. data/lib/deprec/recipes/trac.rb +239 -62
  55. data/lib/deprec/recipes/ubuntu.rb +18 -100
  56. data/lib/deprec/recipes/users.rb +90 -0
  57. data/lib/deprec/recipes/utils.rb +58 -0
  58. data/lib/deprec/recipes/vnstat.rb +85 -0
  59. data/lib/deprec/recipes/web/apache.rb +119 -0
  60. data/lib/deprec/recipes/web/nginx.rb +172 -0
  61. data/lib/deprec/recipes/wordpress.rb +96 -0
  62. data/lib/deprec/recipes/wpmu.rb +103 -0
  63. data/lib/deprec/recipes/xen.rb +267 -0
  64. data/lib/deprec/recipes/xentools.rb +75 -0
  65. data/lib/deprec/templates/aoe/aoe-init +55 -0
  66. data/lib/deprec/templates/aoe/fence_aoemask +351 -0
  67. data/lib/deprec/templates/apache/namevirtualhosts.conf +5 -0
  68. data/lib/deprec/templates/apt/sources.list +18 -0
  69. data/lib/deprec/templates/apt_mirror/apt-mirror-cron +4 -0
  70. data/lib/deprec/templates/apt_mirror/mirror.list +33 -0
  71. data/lib/deprec/templates/ar_sendmail/logrotate.conf.erb +9 -0
  72. data/lib/deprec/templates/ar_sendmail/monit.conf.erb +5 -0
  73. data/lib/deprec/templates/ddclient/ddclient.conf.erb +11 -0
  74. data/lib/deprec/templates/ddclient/ddclient.erb +15 -0
  75. data/lib/deprec/templates/deprec/caprc.erb +14 -0
  76. data/lib/deprec/templates/heartbeat/authkeys.erb +2 -0
  77. data/lib/deprec/templates/heartbeat/ha.cf.erb +15 -0
  78. data/lib/deprec/templates/heartbeat/haresources.erb +1 -0
  79. data/lib/deprec/templates/logrotate/logrotate.conf.erb +32 -0
  80. data/lib/deprec/templates/mongrel/apache_vhost.erb +148 -0
  81. data/lib/deprec/templates/mongrel/logrotate.conf.erb +11 -0
  82. data/lib/deprec/{third_party/mongrel_cluster/resources/mongrel_cluster → templates/mongrel/mongrel_cluster-init-script} +19 -6
  83. data/lib/deprec/templates/mongrel/mongrel_cluster.yml.erb +10 -0
  84. data/lib/deprec/templates/mongrel/monit.conf.erb +17 -0
  85. data/lib/deprec/templates/mongrel/nginx_vhost.erb +41 -0
  86. data/lib/deprec/templates/monit/monit-init-script +104 -0
  87. data/lib/deprec/templates/monit/monitrc.erb +227 -0
  88. data/lib/deprec/templates/monit/nothing +0 -0
  89. data/lib/deprec/templates/mysql/create_databases.sql +20 -0
  90. data/lib/deprec/templates/mysql/database.yml.prod +6 -0
  91. data/lib/deprec/templates/mysql/database.yml.stage +6 -0
  92. data/lib/deprec/templates/mysql/my.cnf.erb +140 -0
  93. data/lib/deprec/templates/mysql/sphinx.conf.prod +542 -0
  94. data/lib/deprec/templates/mysql/sphinx.conf.stage +542 -0
  95. data/lib/deprec/templates/nagios/cgi.cfg.erb +321 -0
  96. data/lib/deprec/templates/nagios/check_linux_free_memory.pl +118 -0
  97. data/lib/deprec/templates/nagios/check_mongrel_cluster.rb +82 -0
  98. data/lib/deprec/templates/nagios/commands.cfg.erb +240 -0
  99. data/lib/deprec/templates/nagios/contacts.cfg.erb +57 -0
  100. data/lib/deprec/templates/nagios/hosts.cfg.erb +143 -0
  101. data/lib/deprec/templates/nagios/htpasswd.users +1 -0
  102. data/lib/deprec/templates/nagios/localhost.cfg.erb +157 -0
  103. data/lib/deprec/templates/nagios/nagios.cfg.erb +1274 -0
  104. data/lib/deprec/templates/nagios/nagios_apache_vhost.conf.erb +45 -0
  105. data/lib/deprec/templates/nagios/nrpe.cfg.erb +210 -0
  106. data/lib/deprec/templates/nagios/nrpe.xinetd.erb +16 -0
  107. data/lib/deprec/templates/nagios/resource.cfg.erb +34 -0
  108. data/lib/deprec/templates/nagios/services.cfg.erb +79 -0
  109. data/lib/deprec/templates/nagios/templates.cfg.erb +9 -0
  110. data/lib/deprec/templates/nagios/timeperiods.cfg.erb +94 -0
  111. data/lib/deprec/templates/network/hostname.erb +1 -0
  112. data/lib/deprec/templates/network/hosts.erb +2 -0
  113. data/lib/deprec/templates/network/interfaces.erb +18 -0
  114. data/lib/deprec/templates/network/resolv.conf.erb +6 -0
  115. data/lib/deprec/templates/nginx/logrotate.conf.erb +13 -0
  116. data/lib/deprec/templates/nginx/mime.types.erb +70 -0
  117. data/lib/deprec/templates/nginx/nginx-init-script +62 -0
  118. data/lib/deprec/templates/nginx/nginx.conf.erb +125 -0
  119. data/lib/deprec/templates/nginx/nginx.logrotate.d +12 -0
  120. data/lib/deprec/templates/nginx/nothing.conf +1 -0
  121. data/lib/deprec/templates/nginx/rails_nginx_vhost.conf.erb +41 -0
  122. data/lib/deprec/templates/ntp/ntp.conf.erb +42 -0
  123. data/lib/deprec/templates/passenger/apache_vhost.erb +21 -0
  124. data/lib/deprec/templates/passenger/passenger.conf.erb +21 -0
  125. data/lib/deprec/templates/passenger/passenger.load.erb +3 -0
  126. data/lib/deprec/templates/postfix/aliases.erb +3 -0
  127. data/lib/deprec/templates/postfix/dynamicmaps.cf.erb +8 -0
  128. data/lib/deprec/templates/{postfix_main.conf → postfix/main.cf.erb} +6 -8
  129. data/lib/deprec/templates/postfix/master.cf.erb +77 -0
  130. data/lib/deprec/templates/sphinx/monit.conf.erb +5 -0
  131. data/lib/deprec/templates/ssh/ssh_config.erb +50 -0
  132. data/lib/deprec/templates/ssh/sshd_config.erb +78 -0
  133. data/lib/deprec/templates/ssl/make-ssl-cert +138 -0
  134. data/lib/deprec/templates/ssl/ssl-cert-snakeoil.key +15 -0
  135. data/lib/deprec/templates/ssl/ssl-cert-snakeoil.pem +19 -0
  136. data/lib/deprec/templates/starling/monit.conf.erb +14 -0
  137. data/lib/deprec/templates/starling/starling-init-script.erb +71 -0
  138. data/lib/deprec/templates/subversion/svn.apache.vhost.erb +43 -0
  139. data/lib/deprec/templates/trac/apache_vhost.conf.erb +24 -0
  140. data/lib/deprec/templates/trac/nginx_vhost.conf.erb +26 -0
  141. data/lib/deprec/templates/trac/trac.ini.erb +169 -0
  142. data/lib/deprec/templates/trac/trac_deprec.png +0 -0
  143. data/lib/deprec/templates/trac/tracd-init.erb +43 -0
  144. data/lib/deprec/templates/trac/users.htdigest.erb +0 -0
  145. data/lib/deprec/templates/vnstat/config.php +57 -0
  146. data/lib/deprec/templates/wordpress/apache2_wordpress_vhost.conf.erb +31 -0
  147. data/lib/deprec/templates/wordpress/wp-config.php.erb +31 -0
  148. data/lib/deprec/templates/wpmu/apache_vhost.conf.erb +13 -0
  149. data/lib/deprec/templates/xen/network-bridge-wrapper +3 -0
  150. data/lib/deprec/templates/xen/xend-config.sxp.erb +195 -0
  151. data/lib/deprec/templates/xen/xend-init.erb +57 -0
  152. data/lib/deprec/templates/xen/xendomains.erb +137 -0
  153. data/lib/deprec/templates/xentools/15-disable-hwclock +40 -0
  154. data/lib/deprec/templates/xentools/40-setup-networking +145 -0
  155. data/lib/deprec/templates/xentools/xen-tools.conf.erb +276 -0
  156. data/lib/deprec/templates/xentools/xm.tmpl.erb +138 -0
  157. data/lib/deprec_cmd_completion.sh +26 -0
  158. data/lib/vmbuilder_plugins/all.rb +20 -0
  159. data/lib/vmbuilder_plugins/apt.rb +93 -0
  160. data/lib/vmbuilder_plugins/emerge.rb +76 -0
  161. data/lib/{deprec/third_party/vmbuilder/plugins → vmbuilder_plugins}/gem.rb +10 -17
  162. data/lib/{deprec/third_party/vmbuilder/plugins → vmbuilder_plugins}/std.rb +69 -19
  163. metadata +204 -55
  164. data/bin/deprec +0 -35
  165. data/docs/README.slicehost +0 -14
  166. data/docs/README.svn_trac +0 -19
  167. data/lib/deprec/capistrano_extensions/actor_extensions.rb +0 -89
  168. data/lib/deprec/capistrano_extensions/cli_extensions.rb +0 -38
  169. data/lib/deprec/capistrano_extensions/deprec_extensions.rb +0 -137
  170. data/lib/deprec/generators/deprec/USAGE +0 -11
  171. data/lib/deprec/generators/deprec/deprec_generator.rb +0 -24
  172. data/lib/deprec/generators/deprec/templates/deploy.rb +0 -90
  173. data/lib/deprec/generators/loader.rb +0 -20
  174. data/lib/deprec/recipes/apache.rb +0 -91
  175. data/lib/deprec/recipes/cache_svn.rb +0 -74
  176. data/lib/deprec/recipes/vmware.rb +0 -114
  177. data/lib/deprec/templates/trac.ini.erb +0 -106
  178. data/lib/deprec/third_party/THIRD_PARTY_README +0 -12
  179. data/lib/deprec/third_party/mongrel_cluster/LICENSE +0 -506
  180. data/lib/deprec/third_party/mongrel_cluster/recipes.rb +0 -96
  181. data/lib/deprec/third_party/railsmachine/LICENSE +0 -506
  182. data/lib/deprec/third_party/railsmachine/recipes/apache.rb +0 -92
  183. data/lib/deprec/third_party/railsmachine/recipes/mysql.rb +0 -73
  184. data/lib/deprec/third_party/railsmachine/recipes/templates/httpd-ssl.conf +0 -80
  185. data/lib/deprec/third_party/railsmachine/recipes/templates/httpd.conf +0 -57
  186. data/lib/deprec/third_party/vmbuilder/plugins.rb +0 -8
  187. data/lib/deprec/third_party/vmbuilder/plugins/apt.rb +0 -144
  188. data/resources/capistrano_include_dotfiles.patch +0 -17
@@ -0,0 +1,93 @@
1
+ # Copyright 2006-2008 by Mike Bailey. All rights reserved.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :deprec do
4
+ namespace :network do
5
+
6
+ set(:network_number_of_ports) {
7
+ Capistrano::CLI.ui.ask "Number of network interfaces" do |q|
8
+ q.default = 1
9
+ end
10
+ }
11
+
12
+ default_network = ''
13
+ set(:network_interfaces) {
14
+ result = {}
15
+ network_number_of_ports.to_i.times do |iface|
16
+ default_network = "192.168.#{iface+1}"
17
+ result[iface] = {}
18
+ result[iface][:address] = Capistrano::CLI.ui.ask "address" do |q|
19
+ q.default = "#{default_network}.10"
20
+ end
21
+ default_network = result[iface][:address].split('.').slice(0,3).join('.')
22
+ result[iface][:netmask] = Capistrano::CLI.ui.ask "netmask" do |q|
23
+ q.default = "255.255.255.0"
24
+ end
25
+ result[iface][:broadcast] = Capistrano::CLI.ui.ask "broadcast" do |q|
26
+ q.default = "#{default_network}.255"
27
+ end
28
+ end
29
+ result
30
+ }
31
+ set(:network_hostname) {
32
+ Capistrano::CLI.ui.ask "Enter the hostname for the server" do |q|
33
+ # q.validate = /add hostname validation here/
34
+ end
35
+ }
36
+ set(:network_gateway) {
37
+ Capistrano::CLI.ui.ask "default gateway" do |q|
38
+ q.default = "#{default_network}.1"
39
+ end
40
+ }
41
+ set(:network_dns_nameservers) {
42
+ Capistrano::CLI.ui.ask "dns nameservers (separated by spaces)" do |q|
43
+ q.default = '203.8.183.1 4.2.2.1'
44
+ end
45
+ }
46
+ set(:network_dns_search_path) {
47
+ Capistrano::CLI.ui.ask "dns search domains (separated by spaces)" do |q|
48
+ q.default = nil
49
+ end
50
+ }
51
+
52
+ SYSTEM_CONFIG_FILES[:network] = [
53
+
54
+ {:template => "interfaces.erb",
55
+ :path => '/etc/network/interfaces',
56
+ :mode => 0644,
57
+ :owner => 'root:root'},
58
+
59
+ {:template => "hosts.erb",
60
+ :path => '/etc/hosts',
61
+ :mode => 0644,
62
+ :owner => 'root:root'},
63
+
64
+ {:template => "hostname.erb",
65
+ :path => '/etc/hostname',
66
+ :mode => 0644,
67
+ :owner => 'root:root'},
68
+
69
+ {:template => "resolv.conf.erb",
70
+ :path => '/etc/resolv.conf',
71
+ :mode => 0644,
72
+ :owner => 'root:root'}
73
+
74
+ ]
75
+
76
+ # XXX need to set the order for these as it breaks sudo currently
77
+ desc "Update system networking configuration"
78
+ task :config do
79
+ SYSTEM_CONFIG_FILES[:network].each do |file|
80
+ deprec2.render_template(:network, file.merge(:remote=>true))
81
+ end
82
+ end
83
+
84
+ desc "Restart network interface"
85
+ task :restart do
86
+ sudo '/etc/init.d/networking restart'
87
+ end
88
+
89
+
90
+ end
91
+ end
92
+
93
+ end
@@ -0,0 +1,103 @@
1
+ # Copyright 2006-2008 by Mike Bailey. All rights reserved.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :deprec do
4
+ namespace :ntp do
5
+
6
+ # Install
7
+
8
+ desc "Install ntp"
9
+ task :install do
10
+ install_deps
11
+ SYSTEM_CONFIG_FILES[:ntp].each do |file|
12
+ deprec2.render_template(:ntp, file.merge(:remote => true))
13
+ end
14
+ activate
15
+ end
16
+
17
+ # install dependencies for nginx
18
+ task :install_deps do
19
+ apt.install( {:base => %w(ntp)}, :stable )
20
+ end
21
+
22
+
23
+ # Configure
24
+
25
+ SYSTEM_CONFIG_FILES[:ntp] = [
26
+
27
+ {:template => 'ntp.conf.erb',
28
+ :path => '/etc/ntp.conf',
29
+ :mode => 0755,
30
+ :owner => 'root:root'}
31
+ ]
32
+
33
+ desc "Generate ntp config from template."
34
+ task :config_gen do
35
+ SYSTEM_CONFIG_FILES[:ntp].each do |file|
36
+ deprec2.render_template(:ntp, file)
37
+ end
38
+ end
39
+
40
+ desc "Push ntp config files to server"
41
+ task :config do
42
+ deprec2.push_configs(:ntp, SYSTEM_CONFIG_FILES[:ntp])
43
+ end
44
+
45
+ desc 'Enable ntp start scripts on server.'
46
+ task :activate do
47
+ send(run_method, "update-rc.d ntp defaults")
48
+ end
49
+
50
+ desc 'Disable ntp start scripts on server.'
51
+ task :deactivate do
52
+ send(run_method, "update-rc.d -f ntp remove")
53
+ end
54
+
55
+
56
+ # Control
57
+
58
+ desc "Start ntp"
59
+ task :start do
60
+ send(run_method, "/etc/init.d/ntp start")
61
+ end
62
+
63
+ desc "Stop ntp"
64
+ task :stop do
65
+ send(run_method, "/etc/init.d/ntp stop")
66
+ end
67
+
68
+ desc "Restart ntp"
69
+ task :restart do
70
+ send(run_method, "/etc/init.d/ntp restart")
71
+ end
72
+
73
+ desc "Reload ntp"
74
+ task :reload do
75
+ puts "use 'restart' instead"
76
+ exit 1
77
+ end
78
+
79
+ task :backup, :roles => :web do
80
+ # there's nothing to backup for ntp
81
+ end
82
+
83
+ task :restore, :roles => :web do
84
+ # there's nothing to store for ntp
85
+ end
86
+
87
+ end
88
+ end
89
+ end
90
+
91
+
92
+ # Some nice nagios checks
93
+ #
94
+ # Check important hosts have expected DNS
95
+ #
96
+ # root@sm02:/usr/local/nagios/libexec# ./check_dns --hostname=astro.blocksglobal.com --expected-address=116.240.200.167
97
+ # DNS OK: 0.009 seconds response time. astro.blocksglobal.com returns 116.240.200.167|time=0.008744s;;;0.000000
98
+ #
99
+ #
100
+
101
+ # reconfigure timezone on hardy
102
+ #
103
+ # dpkg-reconfigure tzdata
@@ -0,0 +1,58 @@
1
+ # Copyright 2006-2008 by Mike Bailey. All rights reserved.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :deprec do
4
+ namespace :php do
5
+
6
+ desc "Install PHP"
7
+ task :install do
8
+ install_deps
9
+ end
10
+
11
+ # Install dependencies for php
12
+ task :install_deps do
13
+ apt.install( {:base => %w(php5 php5-mysql)}, :stable )
14
+ end
15
+
16
+ desc "generate config file for php"
17
+ task :config_gen do
18
+ # not yet implemented
19
+ end
20
+
21
+ desc "deploy config file for php"
22
+ task :config, :roles => :web do
23
+ # not yet implemented
24
+ end
25
+
26
+ task :start, :roles => :web do
27
+ # not applicable
28
+ end
29
+
30
+ task :stop, :roles => :web do
31
+ # not applicable
32
+ end
33
+
34
+ task :restart, :roles => :web do
35
+ # not applicable
36
+ end
37
+
38
+ desc "enable php in webserver"
39
+ task :activate, :roles => :web do
40
+ # not yet implemented
41
+ end
42
+
43
+ desc "disable php in webserver"
44
+ task :deactivate, :roles => :web do
45
+ # not yet implemented
46
+ end
47
+
48
+ task :backup, :roles => :web do
49
+ # not applicable
50
+ end
51
+
52
+ task :restore, :roles => :web do
53
+ # not applicable
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,115 @@
1
+ # Copyright 2006-2008 by Mike Bailey. All rights reserved.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ # XXX not complete
4
+ namespace :deprec do
5
+ namespace :postfix do
6
+
7
+ set(:postfix_relayhost) { Capistrano::CLI.ui.ask "What host should we relay mail through?" }
8
+
9
+ desc "Install Postfix"
10
+ task :install, :roles => :mail do
11
+ install_deps
12
+ end
13
+
14
+ # Install dependencies for Postfix
15
+ task :install_deps do
16
+ # mutt and mailx are useful tools for testing mail
17
+ # e.g. echo test | mail test@gmail.com
18
+ apt.install( {:base => %w(postfix mutt mailx)}, :stable )
19
+ end
20
+
21
+ # This is my default Postfix setup on servers that
22
+ # aren't my main outgoing mailserver.
23
+ # It accepts mail from localhost only and relays
24
+ # all mail to a master mailserver for delivery.
25
+ #
26
+ SYSTEM_CONFIG_FILES[:postfix] = [
27
+
28
+ {:template => "main.cf.erb",
29
+ :path => '/etc/postfix/main.cf',
30
+ :mode => 0644,
31
+ :owner => 'root:root'},
32
+
33
+ {:template => "master.cf.erb",
34
+ :path => '/etc/postfix/master.cf',
35
+ :mode => 0644,
36
+ :owner => 'root:root'},
37
+
38
+ {:template => "dynamicmaps.cf.erb",
39
+ :path => '/etc/postfix/dynamicmaps.cf',
40
+ :mode => 0644,
41
+ :owner => 'root:root'},
42
+
43
+ {:template => "aliases.erb",
44
+ :path => '/etc/aliases',
45
+ :mode => 0644,
46
+ :owner => 'root:root'}
47
+
48
+ ]
49
+
50
+ desc 'Generate configuration files(s) for postfix'
51
+ task :config_gen do
52
+ SYSTEM_CONFIG_FILES[:postfix].each do |file|
53
+ deprec2.render_template(:postfix, file)
54
+ end
55
+ end
56
+
57
+ desc 'Deploy configuration files(s) for postfix'
58
+ task :config, :roles => :mail, :except => { :master => true } do
59
+ deprec2.push_configs(:postfix, SYSTEM_CONFIG_FILES[:postfix])
60
+ send(run_method, "/usr/bin/newaliases")
61
+ reload
62
+ end
63
+
64
+ desc "Start Postfix"
65
+ task :start, :roles => :mail, :except => { :master => true } do
66
+ send(run_method, "/etc/init.d/postfix start")
67
+ end
68
+
69
+ desc "Stop Postfix"
70
+ task :stop, :roles => :mail, :except => { :master => true } do
71
+ send(run_method, "/etc/init.d/postfix stop")
72
+ end
73
+
74
+ desc "Restart Postfix"
75
+ task :restart, :roles => :mail, :except => { :master => true } do
76
+ send(run_method, "/etc/init.d/postfix restart")
77
+ end
78
+
79
+ desc "Reload Postfix"
80
+ task :reload, :roles => :mail, :except => { :master => true } do
81
+ send(run_method, "/etc/init.d/postfix reload")
82
+ end
83
+
84
+ task :activate, :roles => :web do
85
+ end
86
+
87
+ task :deactivate, :roles => :web do
88
+ end
89
+
90
+ task :backup, :roles => :web do
91
+ end
92
+
93
+ task :restore, :roles => :web do
94
+ end
95
+
96
+ end
97
+ end
98
+ end
99
+
100
+
101
+ # Capistrano::Configuration.instance(:must_exist).load do
102
+ #
103
+ # namespace :deprec do namespace :nginx do
104
+ #
105
+ # #Craig: I've kept this generic rather than calling the task setup postfix.
106
+ # # if people want other smtp servers, it could be configurable
107
+ # desc "install and configure postfix"
108
+ # task :setup_smtp_server do
109
+ # install_postfix
110
+ # set :postfix_destination_domains, [domain] + apache_server_aliases
111
+ # deprec.render_template_to_file('postfix_main', '/etc/postfix/main.cf')
112
+ # end
113
+ #
114
+ # end end
115
+ # end
@@ -1,61 +1,306 @@
1
- Capistrano.configuration(:must_exist).load do
2
-
1
+ # Copyright 2006-2008 by Mike Bailey. 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 }
3
8
  set :database_yml_in_scm, true
9
+ set :app_symlinks, nil
10
+ set :rails_env, 'production'
11
+ set :gems_for_project, nil # Array of gems to be installed for app
12
+ set :packages_for_project, nil # Array of packages to be installed for app
13
+ set :shared_dirs, nil # Array of directories that should be created under shared/
14
+ # and linked to in the project
4
15
 
5
- # database.yml stuff
6
- #
7
- # XXX DRY this up
8
- # I don't know how to let :gen_db_yml check if values have been set.
9
- #
10
- # if (self.respond_to?("db_host_#{rails_env}".to_sym)) # doesn't seem to work
11
-
12
- set :db_host_default, lambda { Capistrano::CLI.prompt 'Enter database host', 'localhost'}
13
- set :db_host_staging, lambda { db_host_default }
14
- set :db_host_production, lambda { db_host_default }
15
-
16
- set :db_name_default, lambda { Capistrano::CLI.prompt 'Enter database name', "#{application}_#{rails_env}" }
17
- set :db_name_staging, lambda { db_name_default }
18
- set :db_name_production, lambda { db_name_default }
19
-
20
- set :db_user_default, lambda { Capistrano::CLI.prompt 'Enter database user', 'root' }
21
- set :db_user_staging, lambda { db_user_default }
22
- set :db_user_production, lambda { db_user_default }
23
-
24
- set :db_pass_default, lambda { Capistrano::CLI.prompt 'Enter database pass', '' }
25
- set :db_pass_staging, lambda { db_pass_default }
26
- set :db_pass_production, lambda { db_pass_default }
27
-
28
- set :db_adaptor_default, lambda { Capistrano::CLI.prompt 'Enter database adaptor', 'mysql' }
29
- set :db_adaptor_staging, lambda { db_adaptor_default }
30
- set :db_adaptor_production, lambda { db_adaptor_default }
31
-
32
- set :db_socket_default, lambda { Capistrano::CLI.prompt('Enter database socket', '')}
33
- set :db_socket_staging, lambda { db_socket_default }
34
- set :db_socket_production, lambda { db_socket_default }
35
-
36
-
37
- task :generate_database_yml, :roles => :app do
38
- database_configuration = render :template => <<-EOF
39
- #{rails_env}:
40
- adapter: #{self.send("db_adaptor_#{rails_env}")}
41
- database: #{self.send("db_name_#{rails_env}")}
42
- username: #{self.send("db_user_#{rails_env}")}
43
- password: #{self.send("db_pass_#{rails_env}")}
44
- host: #{self.send("db_host_#{rails_env}")}
45
- socket: #{self.send("db_socket_#{rails_env}")}
46
- EOF
47
- run "mkdir -p #{deploy_to}/#{shared_dir}/config"
48
- put database_configuration, "#{deploy_to}/#{shared_dir}/config/database.yml"
16
+ # Hook into the default capistrano deploy tasks
17
+ before 'deploy:setup', :except => { :no_release => true } do
18
+ top.deprec.rails.setup_user_perms
19
+ top.deprec.rails.create_app_user_and_group
20
+ top.deprec.rails.setup_paths
21
+ top.deprec.rails.setup_shared_dirs
22
+ top.deprec.rails.install_packages_for_project
23
+ top.deprec.rails.install_gems_for_project
49
24
  end
50
-
51
- task :after_update_code, :roles => :app do
52
- symlink_database_yml unless database_yml_in_scm
25
+
26
+ after 'deploy:setup', :except => { :no_release => true } do
27
+ top.deprec.rails.create_config_dir
28
+ top.deprec.rails.config_gen
29
+ top.deprec.rails.config
30
+ top.deprec.rails.activate_services
31
+ top.deprec.rails.set_perms_on_shared_and_releases
32
+ top.deprec.web.reload
33
+ top.deprec.rails.setup_database
53
34
  end
54
-
55
- desc "Link in the production database.yml"
56
- task :symlink_database_yml, :roles => :app do
57
- run "rm -f #{current_path}/config/database.yml"
58
- run "ln -nfs #{deploy_to}/#{shared_dir}/config/database.yml #{release_path}/config/database.yml"
35
+
36
+ after 'deploy:symlink', :roles => :app do
37
+ top.deprec.rails.symlink_shared_dirs
38
+ top.deprec.rails.symlink_database_yml unless database_yml_in_scm
39
+ top.deprec.rails.make_writable_by_app
40
+ set_owner_of_environment_rb if web_server_type.to_s == 'passenger'
41
+ end
42
+
43
+ after :deploy, :roles => :app do
44
+ deploy.cleanup
45
+ end
46
+
47
+ namespace :deprec do
48
+ namespace :rails do
49
+
50
+ task :setup_database, :roles => :db do
51
+ if ! roles[:db].servers.empty? # Some apps don't use database!
52
+ deprec2.read_database_yml
53
+ top.deprec.db.create_user
54
+ top.deprec.db.create_database
55
+ top.deprec.db.grant_user_access_to_database
56
+ end
57
+ end
58
+
59
+ task :install, :roles => :app do
60
+ install_deps
61
+ install_gems
62
+ end
63
+
64
+ task :install_deps do
65
+ apt.install( {:base => %w(libmysqlclient15-dev sqlite3 libsqlite3-ruby libsqlite3-dev libpq-dev)}, :stable )
66
+ end
67
+
68
+ # install some required ruby gems
69
+ task :install_gems do
70
+ gem2.install 'sqlite3-ruby'
71
+ gem2.install 'mysql'
72
+ gem2.install 'ruby-pg'
73
+ gem2.install 'rails'
74
+ gem2.install 'rake'
75
+ gem2.install 'rspec'
76
+ end
77
+
78
+ desc <<-DESC
79
+ Install full rails stack on a stock standard ubuntu server (7.10, 8.04)
80
+ DESC
81
+ task :install_stack do
82
+
83
+ top.deprec.ruby.install
84
+ top.deprec.web.install # Uses value of web_server_type
85
+ top.deprec.svn.install
86
+ top.deprec.git.install
87
+ top.deprec.app.install # Uses value of app_server_type
88
+ top.deprec.monit.install
89
+ top.deprec.rails.install
90
+ top.deprec.logrotate.install
91
+
92
+ # We not longer install database server as part of this task.
93
+ # There is too much danger that someone will wreck an existing
94
+ # shared database.
95
+ #
96
+ # Install database server with:
97
+ #
98
+ # cap deprec:db:install
99
+ end
100
+
101
+ task :install_rails_stack do
102
+ puts "deprecated: this task is now called install_stack"
103
+ install_stack
104
+ end
105
+
106
+ desc "Generate config files for rails app."
107
+ task :config_gen do
108
+ top.deprec.web.config_gen_project
109
+ top.deprec.app.config_gen_project
110
+ end
111
+
112
+ desc "Push out config files for rails app."
113
+ task :config do
114
+ top.deprec.web.config_project
115
+ top.deprec.app.config_project
116
+ end
117
+
118
+ task :create_config_dir, :roles => :app do
119
+ deprec2.mkdir("#{shared_path}/config", :group => group, :mode => 0775, :via => :sudo)
120
+ end
121
+
122
+ # XXX This should be restricted a bit to limit what app can write to. - Mike
123
+ desc "set group ownership and permissions on dirs app server needs to write to"
124
+ task :make_writable_by_app, :roles => :app do
125
+ tmp_dir = "#{deploy_to}/current/tmp"
126
+ shared_dir = "#{deploy_to}/shared"
127
+ # XXX Factor this out
128
+ files = ["#{mongrel_log_dir}/mongrel.log", "#{mongrel_log_dir}/#{rails_env}.log"]
129
+
130
+ sudo "chgrp -R #{app_group} #{tmp_dir} #{shared_dir}"
131
+ sudo "chmod -R g+w #{tmp_dir} #{shared_dir}"
132
+ # set owner and group of log files
133
+ files.each { |file|
134
+ sudo "touch #{file}"
135
+ sudo "chown #{app_user} #{file}"
136
+ sudo "chgrp #{app_group} #{file}"
137
+ sudo "chmod g+w #{file}"
138
+ }
139
+ end
140
+
141
+ desc "Create deployment group and add current user to it"
142
+ task :setup_user_perms, :roles => [:app, :web] do
143
+ deprec2.groupadd(group)
144
+ deprec2.add_user_to_group(user, group)
145
+ deprec2.groupadd(app_group)
146
+ deprec2.add_user_to_group(user, app_group)
147
+ # we've just added ourself to a group - need to teardown connection
148
+ # so that next command uses new session where we belong in group
149
+ deprec2.teardown_connections
150
+ end
151
+
152
+ desc "Create user and group for application to run as"
153
+ task :create_app_user_and_group, :roles => :app do
154
+ deprec2.groupadd(app_group)
155
+ deprec2.useradd(app_user, :group => app_group, :homedir => false)
156
+ # Set the primary group for the user the application runs as (in case
157
+ # user already existed when previous command was run)
158
+ sudo "usermod --gid #{app_group} #{app_user}"
159
+ end
160
+
161
+ task :set_perms_on_shared_and_releases, :roles => :app do
162
+ releases = File.join(deploy_to, 'releases')
163
+ sudo "chgrp -R #{group} #{shared_path} #{releases}"
164
+ sudo "chmod -R g+w #{shared_path} #{releases}"
165
+ end
166
+
167
+ # Passenger runs Rails as the owner of this file.
168
+ task :set_owner_of_environment_rb, :roles => :app do
169
+ sudo "chown #{app_user} #{current_path}/config/environment.rb"
170
+ end
171
+
172
+ # Setup database server.
173
+ task :setup_db, :roles => :db, :only => { :primary => true } do
174
+ top.deprec.mysql.setup
175
+ end
176
+
177
+ # setup extra paths required for deployment
178
+ task :setup_paths, :roles => [:app, :web] do
179
+ deprec2.mkdir(deploy_to, :mode => 0775, :group => group, :via => :sudo)
180
+ deprec2.mkdir(shared_path, :mode => 0775, :group => group, :via => :sudo)
181
+ end
182
+
183
+ # Symlink list of files and dirs from shared to current
184
+ #
185
+ # XXX write up explanation
186
+ #
187
+ desc "Setup shared dirs"
188
+ task :setup_shared_dirs, :roles => [:app, :web] do
189
+ if shared_dirs
190
+ shared_dirs.each { |dir| deprec2.mkdir( "#{shared_path}/#{dir}", :via => :sudo ) }
191
+ end
192
+ end
193
+ #
194
+ desc "Symlink shared dirs."
195
+ task :symlink_shared_dirs, :roles => [:app, :web] do
196
+ if shared_dirs
197
+ shared_dirs.each do |dir|
198
+ path = File.split(dir)[0]
199
+ if path != '.'
200
+ deprec2.mkdir("#{current_path}/#{path}")
201
+ end
202
+ run "ln -nfs #{shared_path}/#{dir} #{current_path}/#{dir}"
203
+ end
204
+ end
205
+ end
206
+
207
+ task :install_packages_for_project, :roles => :app do
208
+ if packages_for_project
209
+ apt.install({ :base => packages_for_project }, :stable)
210
+ end
211
+ end
212
+
213
+ task :install_gems_for_project, :roles => :app do
214
+ if gems_for_project
215
+ gems_for_project.each { |gem| gem2.install(gem) }
216
+ end
217
+ end
218
+
219
+ desc "Activate web, app and monit"
220
+ task :activate_services do
221
+ top.deprec.web.activate
222
+ top.deprec.app.activate
223
+ top.deprec.monit.activate
224
+ end
225
+
226
+ # database.yml stuff
227
+ #
228
+ # XXX DRY this up
229
+ # I don't know how to let :gen_db_yml check if values have been set.
230
+ #
231
+ # if (self.respond_to?("db_host_#{rails_env}".to_sym)) # doesn't seem to work
232
+
233
+ set :db_host_default, lambda { Capistrano::CLI.prompt 'Enter database host', 'localhost'}
234
+ set :db_host_staging, lambda { db_host_default }
235
+ set :db_host_production, lambda { db_host_default }
236
+
237
+ set :db_name_default, lambda { Capistrano::CLI.prompt 'Enter database name', "#{application}_#{rails_env}" }
238
+ set :db_name_staging, lambda { db_name_default }
239
+ set :db_name_production, lambda { db_name_default }
240
+
241
+ set :db_user_default, lambda { Capistrano::CLI.prompt 'Enter database user', 'root' }
242
+ set :db_user_staging, lambda { db_user_default }
243
+ set :db_user_production, lambda { db_user_default }
244
+
245
+ set :db_pass_default, lambda { Capistrano::CLI.prompt 'Enter database pass', '' }
246
+ set :db_pass_staging, lambda { db_pass_default }
247
+ set :db_pass_production, lambda { db_pass_default }
248
+
249
+ set :db_adaptor_default, lambda { Capistrano::CLI.prompt 'Enter database adaptor', 'mysql' }
250
+ set :db_adaptor_staging, lambda { db_adaptor_default }
251
+ set :db_adaptor_production, lambda { db_adaptor_default }
252
+
253
+ set :db_socket_default, lambda { Capistrano::CLI.prompt('Enter database socket', '')}
254
+ set :db_socket_staging, lambda { db_socket_default }
255
+ set :db_socket_production, lambda { db_socket_default }
256
+
257
+ task :generate_database_yml, :roles => :app do
258
+ database_configuration = render :template => <<-EOF
259
+ #{rails_env}:
260
+ adapter: #{self.send("db_adaptor_#{rails_env}")}
261
+ database: #{self.send("db_name_#{rails_env}")}
262
+ username: #{self.send("db_user_#{rails_env}")}
263
+ password: #{self.send("db_pass_#{rails_env}")}
264
+ host: #{self.send("db_host_#{rails_env}")}
265
+ socket: #{self.send("db_socket_#{rails_env}")}
266
+ EOF
267
+ run "mkdir -p #{deploy_to}/#{shared_dir}/config"
268
+ put database_configuration, "#{deploy_to}/#{shared_dir}/config/database.yml"
269
+ end
270
+
271
+ desc "Link in the production database.yml"
272
+ task :symlink_database_yml, :roles => :app do
273
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
274
+ end
275
+
276
+ end
277
+
278
+ namespace :database do
279
+
280
+ desc "Create database"
281
+ task :create, :roles => :db do
282
+ run "cd #{deploy_to}/current && rake db:create RAILS_ENV=#{rails_env}"
283
+ end
284
+
285
+ desc "Run database migrations"
286
+ task :migrate, :roles => :db do
287
+ run "cd #{deploy_to}/current && rake db:migrate RAILS_ENV=#{rails_env}"
288
+ end
289
+
290
+ desc "Run database migrations"
291
+ task :schema_load, :roles => :db do
292
+ run "cd #{deploy_to}/current && rake db:schema:load RAILS_ENV=#{rails_env}"
293
+ end
294
+
295
+ desc "Roll database back to previous migration"
296
+ task :rollback, :roles => :db do
297
+ run "cd #{deploy_to}/current && rake db:rollback RAILS_ENV=#{rails_env}"
298
+ end
299
+
300
+ end
301
+
59
302
  end
60
303
 
61
- end
304
+ end
305
+
306
+