sml-rubber 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/VERSION +1 -1
  2. data/generators/vulcanize/templates/apache/config/rubber/deploy-apache.rb +13 -7
  3. data/generators/vulcanize/templates/apache/config/rubber/role/{web → apache}/deflate.conf +0 -0
  4. data/generators/vulcanize/templates/apache/config/rubber/role/{web → apache}/expires.conf +0 -0
  5. data/generators/vulcanize/templates/apache/config/rubber/role/{web → apache}/headers.conf +0 -0
  6. data/generators/vulcanize/templates/apache/config/rubber/role/apache/monit-apache.conf +8 -0
  7. data/generators/vulcanize/templates/apache/config/rubber/role/apache/ports.conf +5 -0
  8. data/generators/vulcanize/templates/apache/config/rubber/role/{web → apache}/setenvif.conf +0 -0
  9. data/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-apache-vhost.conf +62 -0
  10. data/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-apache.auth +7 -0
  11. data/generators/vulcanize/templates/{nginx/config/rubber/role/web_tools/index.html → apache/config/rubber/role/web_tools/tools-index.html} +8 -1
  12. data/generators/vulcanize/templates/apache/config/rubber/rubber-apache.yml +4 -12
  13. data/generators/vulcanize/templates/base/config/deploy.rb +5 -34
  14. data/generators/vulcanize/templates/base/config/rubber/deploy-setup.rb +4 -6
  15. data/generators/vulcanize/templates/base/config/rubber/rubber.yml +29 -3
  16. data/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/role/haproxy/haproxy-mongrel.conf +23 -0
  17. data/generators/vulcanize/templates/{nginx/config/rubber/role/web/nginx.conf → complete_mongrel_mysql/config/rubber/role/nginx/nginx-mongrel.conf} +25 -45
  18. data/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/rubber-complete.yml +41 -0
  19. data/generators/vulcanize/templates/{complete_mysql → complete_mongrel_mysql}/templates.yml +0 -0
  20. data/generators/vulcanize/templates/complete_passenger_mysql/config/rubber/role/haproxy/haproxy-passenger.conf +19 -0
  21. data/generators/vulcanize/templates/complete_passenger_mysql/config/rubber/rubber-complete.yml +40 -0
  22. data/generators/vulcanize/templates/complete_passenger_mysql/templates.yml +3 -1
  23. data/generators/vulcanize/templates/cruise/config/rubber/deploy-cruise.rb +8 -10
  24. data/generators/vulcanize/templates/cruise/config/rubber/role/web_tools/cruise-nginx.conf +1 -1
  25. data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/haproxy-base.conf +26 -0
  26. data/generators/vulcanize/templates/haproxy/config/rubber/role/web_tools/haproxy-nginx.conf +1 -1
  27. data/generators/vulcanize/templates/haproxy/config/rubber/rubber-haproxy.yml +0 -5
  28. data/generators/vulcanize/templates/mongrel/config/rubber/deploy-mongrel.rb +7 -7
  29. data/generators/vulcanize/templates/mongrel/config/rubber/role/{app → mongrel}/mongrel_cluster.yml +4 -4
  30. data/generators/vulcanize/templates/mongrel/config/rubber/role/{app → mongrel}/monit-mongrel.conf +2 -2
  31. data/generators/vulcanize/templates/mongrel/config/rubber/rubber-mongrel.yml +2 -2
  32. data/generators/vulcanize/templates/monit/config/rubber/role/web_tools/monit-admin-nginx.conf +1 -1
  33. data/generators/vulcanize/templates/munin/config/rubber/deploy-munin.rb +17 -1
  34. data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin-nginx.conf +1 -1
  35. data/generators/vulcanize/templates/munin/config/rubber/rubber-munin.yml +1 -1
  36. data/generators/vulcanize/templates/mysql/config/rubber/deploy-mysql.rb +14 -36
  37. data/generators/vulcanize/templates/mysql/config/rubber/role/db/monit-mysql.cnf +1 -1
  38. data/generators/vulcanize/templates/mysql/config/rubber/rubber-mysql.yml +8 -0
  39. data/generators/vulcanize/templates/mysql_cluster/config/rubber/deploy-mysql_cluster.rb +7 -7
  40. data/generators/vulcanize/templates/nginx/config/rubber/deploy-nginx.rb +6 -6
  41. data/generators/vulcanize/templates/nginx/config/rubber/role/{web → nginx}/crontab +0 -0
  42. data/generators/vulcanize/templates/nginx/config/rubber/role/{web → nginx}/monit-nginx.conf +0 -1
  43. data/generators/vulcanize/templates/nginx/config/rubber/role/nginx/nginx.conf +42 -0
  44. data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/nginx-tools.conf +43 -62
  45. data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/tools-index.html +30 -0
  46. data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/tools-nginx.auth +7 -0
  47. data/generators/vulcanize/templates/nginx/config/rubber/rubber-nginx.yml +3 -26
  48. data/generators/vulcanize/templates/passenger/config/rubber/deploy-passenger.rb +13 -40
  49. data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger-sudoers.conf +6 -0
  50. data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger.conf +47 -0
  51. data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/passenger-apache-vhost.conf +46 -0
  52. data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/passenger.conf +10 -0
  53. data/generators/vulcanize/templates/passenger/config/rubber/rubber-passenger.yml +9 -11
  54. data/generators/vulcanize/templates/sphinx/config/rubber/deploy-sphinx.rb +1 -1
  55. data/lib/rubber/cloud/aws.rb +30 -0
  56. data/lib/rubber/instance.rb +53 -2
  57. data/lib/rubber/recipes/rubber.rb +7 -6
  58. data/lib/rubber/recipes/rubber/deploy.rb +22 -1
  59. data/lib/rubber/recipes/rubber/instances.rb +74 -24
  60. data/lib/rubber/recipes/rubber/load_balancers.rb +27 -0
  61. data/lib/rubber/recipes/rubber/security_groups.rb +5 -7
  62. data/lib/rubber/recipes/rubber/setup.rb +50 -14
  63. data/lib/rubber/recipes/rubber/static_ips.rb +7 -7
  64. data/lib/rubber/recipes/rubber/utils.rb +6 -7
  65. data/lib/rubber/recipes/rubber/volumes.rb +8 -8
  66. data/lib/rubber/util.rb +4 -0
  67. data/test/instance_test.rb +55 -0
  68. metadata +32 -18
  69. data/generators/vulcanize/templates/apache/config/rubber/role/web/vhost.conf +0 -27
  70. data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/haproxy.conf +0 -44
  71. data/generators/vulcanize/templates/passenger/config/rubber/role/web/passenger.conf +0 -8
  72. data/generators/vulcanize/templates/passenger/config/rubber/role/web/vhost.conf +0 -29
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.9
1
+ 0.9.10
@@ -4,14 +4,20 @@ namespace :rubber do
4
4
  namespace :apache do
5
5
 
6
6
  rubber.allow_optional_tasks(self)
7
-
7
+
8
+ after "rubber:install_packages", "rubber:apache:custom_install"
9
+
10
+ task :custom_install, :roles => :apache do
11
+ sudo "a2dissite default"
12
+ end
13
+
8
14
  # serial_task can only be called after roles defined - not normally a problem, but
9
15
  # rubber auto-roles don't get defined till after all tasks are defined
10
16
  on :load do
11
- rubber.serial_task self, :serial_restart, :roles => :web do
17
+ rubber.serial_task self, :serial_restart, :roles => :apache do
12
18
  run "/etc/init.d/apache2 restart"
13
19
  end
14
- rubber.serial_task self, :serial_reload, :roles => :web do
20
+ rubber.serial_task self, :serial_reload, :roles => :apache do
15
21
  run "if ! ps ax | grep -v grep | grep -c apache2 &> /dev/null; then /etc/init.d/apache2 start; else /etc/init.d/apache2 reload; fi"
16
22
  end
17
23
  end
@@ -21,22 +27,22 @@ namespace :rubber do
21
27
  after "deploy:restart", "rubber:apache:reload"
22
28
 
23
29
  desc "Stops the apache web server"
24
- task :stop, :roles => :web, :on_error => :continue do
30
+ task :stop, :roles => :apache, :on_error => :continue do
25
31
  run "/etc/init.d/apache2 stop"
26
32
  end
27
33
 
28
34
  desc "Starts the apache web server"
29
- task :start, :roles => :web do
35
+ task :start, :roles => :apache do
30
36
  run "/etc/init.d/apache2 start"
31
37
  end
32
38
 
33
39
  desc "Restarts the apache web server"
34
- task :restart, :roles => :web do
40
+ task :restart, :roles => :apache do
35
41
  serial_restart
36
42
  end
37
43
 
38
44
  desc "Reloads the apache web server"
39
- task :reload, :roles => :web do
45
+ task :reload, :roles => :apache do
40
46
  serial_reload
41
47
  end
42
48
 
@@ -0,0 +1,8 @@
1
+ <%
2
+ @path = '/etc/monit/monit.d/monit-apache.conf'
3
+ %>
4
+ <% PIDFILE = "/var/run/apache2.pid" %>
5
+ check process apache with pidfile <%= PIDFILE %>
6
+ group apache-<%= RUBBER_ENV %>
7
+ start program = "/etc/init.d/apache2 start"
8
+ stop program = "/etc/init.d/apache2 stop"
@@ -0,0 +1,5 @@
1
+ <%
2
+ @path = '/etc/apache2/ports.conf'
3
+ %>
4
+ # empty ports file since other modules contribute which ports to open (vhosts)
5
+
@@ -0,0 +1,62 @@
1
+ <%
2
+ @path = "/etc/apache2/sites-available/#{rubber_env.app_name}-tools"
3
+ @post = "a2enmod rewrite && a2enmod ssl && a2enmod proxy_http && a2enmod proxy_html && a2ensite #{rubber_env.app_name}-tools"
4
+ %>
5
+
6
+ Listen <%= rubber_env.web_tools_port %>
7
+ <VirtualHost *:<%= rubber_env.web_tools_port %>>
8
+ ServerName <%= rubber_env.full_host %>
9
+
10
+ RewriteEngine on
11
+ RewriteCond %{HTTPS} !=on
12
+ RewriteRule ^/(.*)$ https://%{SERVER_NAME}:<%= rubber_env.web_tools_ssl_port %>/$1 [L,R]
13
+ RewriteLog "/var/log/apache2/rewrite.log"
14
+ </VirtualHost>
15
+
16
+ Listen <%= rubber_env.web_tools_ssl_port %>
17
+ <VirtualHost *:<%= rubber_env.web_tools_ssl_port %>>
18
+ ServerName <%= rubber_env.full_host %>
19
+ DocumentRoot /var/www
20
+
21
+ SSLEngine on
22
+ SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
23
+ SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
24
+ SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
25
+ # SSLCertificateFile <%= RUBBER_ROOT %>/config/<%= rubber_env.domain %>.crt
26
+ # SSLCertificateKeyFile <%= RUBBER_ROOT %>/config/<%= rubber_env.domain %>.key
27
+ # SSLCertificateChainFile /etc/ssl/certs/gd_intermediate_bundle.crt
28
+
29
+ <Location />
30
+ AuthType Basic
31
+ AuthName "Rubber Admin Tools"
32
+ AuthUserFile <%= RUBBER_ROOT %>/config/<%= rubber_env.app_name %>.auth
33
+ Require valid-user
34
+
35
+ Allow from all
36
+ </Location>
37
+
38
+ SetOutputFilter proxy-html
39
+
40
+ <% rubber_instances.for_role('haproxy').each do |ic| %>
41
+ ProxyPass /haproxy_<%= ic.name %>/ http://<%= ic.full_name %>:<%= rubber_env.haproxy_admin_port %>/haproxy/
42
+ ProxyPassReverse /haproxy_<%= ic.name %>/ http://<%= ic.full_name %>:<%= rubber_env.haproxy_admin_port %>/haproxy/
43
+ ProxyHTMLURLMap http://<%= ic.full_name %>:<%= rubber_env.haproxy_admin_port %>/ /haproxy_<%= ic.name %>/
44
+ ProxyHTMLURLMap /haproxy/ /haproxy_<%= ic.name %>/
45
+ ProxyHTMLURLMap /haproxy /haproxy_<%= ic.name %>/
46
+ <% end %>
47
+
48
+ <% if cruise_host = rubber_instances.for_role('cruise').first %>
49
+ ProxyPass /cruise/ http://<%= cruise_host.full_name %>:<%= rubber_env.cruise_port %>/
50
+ ProxyPassReverse /cruise/ http://<%= cruise_host.full_name %>:<%= rubber_env.cruise_port %>/
51
+ ProxyHTMLURLMap http://<%= cruise_host.full_name %>:<%= rubber_env.cruise_port %>/ /cruise/
52
+ ProxyHTMLURLMap / /cruise/
53
+ <% end %>
54
+
55
+ <% rubber_instances.each do |ic| %>
56
+ ProxyPass /monit_<%= ic.name %>/ http://<%= ic.full_name %>:<%= rubber_env.monit_admin_port %>/
57
+ ProxyPassReverse /monit_<%= ic.name %>/ http://<%= ic.full_name %>:<%= rubber_env.monit_admin_port %>/
58
+ ProxyHTMLURLMap http://<%= ic.full_name %>:<%= rubber_env.monit_admin_port %>/ /monit_<%= ic.name %>/
59
+ ProxyHTMLURLMap / /monit_<%= ic.name %>/
60
+ <% end %>
61
+
62
+ </VirtualHost>
@@ -0,0 +1,7 @@
1
+ <%
2
+ @path = "#{RUBBER_ROOT}/config/#{rubber_env.app_name}.auth"
3
+ user = rubber_env.web_tools_user || 'admin'
4
+ pass = rubber_env.web_tools_password || rand(1000000000).to_s
5
+ %>
6
+
7
+ <%= `htpasswd -nb #{user} #{pass}` %>
@@ -10,14 +10,21 @@
10
10
  <body>
11
11
  <h1>Rubber Admin Tools</h1>
12
12
  <ul>
13
+
13
14
  <li><a href="/munin/">Munin</a></li>
14
- <li><a href="/cruise/">CruiseControl</a></li>
15
+
16
+ <% if cruise_host = rubber_instances.for_role('cruise').first %>
17
+ <li><a href="http://<%= cruise_host %>/cruise/">CruiseControl</a></li>
18
+ <% end %>
19
+
15
20
  <% rubber_instances.for_role('haproxy').each do |ic| %>
16
21
  <li><a href="/haproxy_<%= ic.name %>/">HAProxy <%= ic.name %></a></li>
17
22
  <% end %>
23
+
18
24
  <% rubber_instances.each do |ic| %>
19
25
  <li><a href="/monit_<%= ic.name %>/">Monit <%= ic.name %></a></li>
20
26
  <% end %>
27
+
21
28
  </ul>
22
29
  </body>
23
30
  </html>
@@ -1,15 +1,7 @@
1
- web_aliases: [www.foo.com *.foo.com]
2
-
3
- security_groups:
4
- web:
5
- description: To open up port 80 for http server on web role
6
- rules:
7
- - protocol: tcp
8
- from_port: 80
9
- to_port: 80
10
- source_ips: [0.0.0.0/0]
11
1
 
12
2
  roles:
13
- web:
3
+ apache:
14
4
  packages: [apache2]
15
- assigned_security_groups: [web]
5
+ roles:
6
+ web_tools:
7
+ packages: [libapache2-mod-proxy-html]
@@ -3,8 +3,9 @@
3
3
  set :rails_env, RUBBER_ENV
4
4
 
5
5
  on :load do
6
- set :application, rubber_cfg.environment.bind().app_name
7
- set :deploy_to, "/mnt/#{application}-#{RUBBER_ENV}"
6
+ set :application, rubber_env.app_name
7
+ set :runner, rubber_env.app_user
8
+ set :deploy_to, "/mnt/#{application}-#{RUBBER_ENV}"
8
9
  end
9
10
 
10
11
  # Use a simple directory tree copy here to make demo easier.
@@ -20,8 +21,7 @@ set :password, nil
20
21
 
21
22
  # Use sudo with user rails for cap deploy:[stop|start|restart]
22
23
  # This way exposed services (mongrel) aren't running as a privileged user
23
- set :use_sudo, true
24
- set :runner, 'rails'
24
+ set :use_sudo, true
25
25
 
26
26
  # How many old releases should be kept around when running "cleanup" task
27
27
  set :keep_releases, 3
@@ -47,38 +47,9 @@ namespace :deploy do
47
47
  end
48
48
  end
49
49
 
50
- # =============================================================================
51
- # TASKS
52
- # =============================================================================
53
-
54
-
50
+ # load in the deploy scripts installed by vulcanize for each rubber module
55
51
  Dir["#{File.dirname(__FILE__)}/rubber/deploy-*.rb"].each do |deploy_file|
56
52
  load deploy_file
57
53
  end
58
54
 
59
- # Don't want to do rubber:config for update_code as that tree isn't official
60
- # until it is 'committed' by the symlink task (and doing so causes it to run
61
- # for bootstrap_db which should only config the db config file). However,
62
- # deploy:migrations doesn't call update, so we need an additional trigger for
63
- # it
64
- after "deploy:update", "rubber:config"
65
- after "deploy:rollback_code", "rubber:config"
66
- before "deploy:migrate", "rubber:config"
67
-
68
- before "rubber:pre_start", "setup_perms"
69
- before "rubber:pre_restart", "setup_perms"
70
55
  after "deploy", "deploy:cleanup"
71
-
72
- # Fix perms because we start server as rails user, but migrate as root,
73
- # server needs to be able to write logs, etc.
74
- task :setup_perms do
75
- run "find #{shared_path} -name cached-copy -prune -o -print | xargs chown #{runner}:#{runner}"
76
- run "chown -R #{runner}:#{runner} #{current_path}/tmp"
77
- end
78
-
79
- # Uncomment this is you want to install gems defined in the rails environment.rb
80
- # after "deploy:update", "install_rails_gems"
81
- task :install_rails_gems do
82
- sudo "sh -c 'cd #{current_path} && RAILS_ENV=#{RUBBER_ENV} rake gems:install'"
83
- end
84
-
@@ -10,7 +10,7 @@ namespace :rubber do
10
10
  # figure out which hosts we have specified enterprise ruby for
11
11
  sys_ruby_hosts = []
12
12
  ent_ruby_hosts = []
13
- rubber_cfg.instance.filtered.each do |ic|
13
+ rubber_instances.filtered.each do |ic|
14
14
  env = rubber_cfg.environment.bind(ic.role_names, ic.name)
15
15
  if env.use_enterprise_ruby
16
16
  ent_ruby_hosts << ic.full_name
@@ -54,13 +54,12 @@ namespace :rubber do
54
54
  src_url = "http://rubyforge.org/frs/download.php/60718/rubygems-#{ver}.tgz"
55
55
  rubber.sudo_script 'install_rubygems', <<-ENDSCRIPT
56
56
  if [[ `gem --version 2>&1` != "#{ver}" ]]; then
57
- wget -qP /tmp #{src_url}
57
+ wget -qNP /tmp #{src_url}
58
58
  tar -C /tmp -xzf /tmp/rubygems-#{ver}.tgz
59
59
  ruby -C /tmp/rubygems-#{ver} setup.rb
60
60
  ln -sf /usr/bin/gem1.8 /usr/bin/gem
61
61
  rm -rf /tmp/rubygems*
62
62
  gem source -l > /dev/null
63
- gem sources -a http://gems.github.com
64
63
  fi
65
64
  ENDSCRIPT
66
65
  end
@@ -93,9 +92,8 @@ namespace :rubber do
93
92
  after "rubber:install_packages", "rubber:base:custom_install"
94
93
  task :custom_install do
95
94
  rubber.sudo_script 'custom_install', <<-ENDSCRIPT
96
- # add the rails user for running app server with
97
- appuser="rails"
98
- if ! id ${appuser} &> /dev/null; then adduser --system --group ${appuser}; fi
95
+ # add the user for running app server with
96
+ if ! id #{rubber_env.app_user} &> /dev/null; then adduser --system --group #{rubber_env.app_user}; fi
99
97
 
100
98
  # add ssh keys for root
101
99
  if [[ ! -f /root/.ssh/id_dsa ]]; then ssh-keygen -q -t dsa -N '' -f /root/.ssh/id_dsa; fi
@@ -11,12 +11,20 @@
11
11
  # packages: [awstats]
12
12
 
13
13
  # REQUIRED: The name of your application
14
- app_name: your_app_name
14
+ app_name: "#{File.basename(RUBBER_ROOT)}"
15
+
16
+ # REQUIRED: The system user to run your app servers as
17
+ app_user: app
15
18
 
16
19
  # REQUIRED: Notification emails (e.g. monit) get sent to this address
17
20
  #
18
21
  admin_email: root@localhost
19
22
 
23
+ # OPTIONAL: If not set, you won't be able to access web_tools
24
+ # server (munin stats, monit status, etc)
25
+ # web_tools_user: admin
26
+ # web_tools_password: sekret
27
+
20
28
  # REQUIRED: The timezone the server should be in
21
29
  timezone: US/Eastern
22
30
 
@@ -127,13 +135,31 @@ auto_security_groups: true
127
135
  # account, or even multiple apps
128
136
  isolate_security_groups: true
129
137
 
138
+ # OPTIONAL: Automatically provision and assign instances to a Cloud provided
139
+ # load balancer.
140
+ load_balancers:
141
+ my_lb_name:
142
+ listeners:
143
+ - protocol: http
144
+ port: 80
145
+ instance_port: 8080
146
+ - protocol: tcp
147
+ port: 443
148
+ instance_port: 8080
149
+ target_roles: [app]
150
+
151
+ isolate_load_balancers: true
152
+
130
153
  # OPTIONAL: Set if you want to use Ruby Enterprise Edition instead of the standard ubuntu one
131
154
  use_enterprise_ruby: false
132
155
 
133
156
  # OPTIONAL: The packages to install on all instances
134
157
  # You can install a specific version of a package by using a sub-array of pkg, version
135
158
  # For example, packages: [[rake, 0.7.1], irb]
136
- packages: [build-essential, ruby-full, ruby1.8-dev, rake, irb]
159
+ packages: [postfix, build-essential, ruby-full, ruby1.8-dev, rake, irb]
160
+
161
+ # OPTIONAL: gem sources to setup for rubygems
162
+ gemsources: ["http://gems.rubyforge.org/", "http://gems.github.com"]
137
163
 
138
164
  # OPTIONAL: The gems to install on all instances
139
165
  # You can install a specific version of a gem by using a sub-array of gem, version
@@ -151,7 +177,7 @@ stop_on_error_cmd: "function error_exit { exit 99; }; trap error_exit ERR"
151
177
  # but this is not always desired for staging, so you can specify a different
152
178
  # set here
153
179
  #
154
- staging_roles: "web,haproxy,app,mysql_master"
180
+ staging_roles: "web,app,db:primary=true"
155
181
 
156
182
 
157
183
  # OPTIONAL: Lets one assign amazon elastic IPs (static IPs) to your instances
@@ -0,0 +1,23 @@
1
+ <%
2
+ @path = "/etc/haproxy/haproxy.cfg"
3
+ @additive = ["# start haproxy mongrel", "# end haproxy mongrel"]
4
+ %>
5
+
6
+ listen mongrel_proxy 0.0.0.0:<%= rubber_env.haproxy_listen_port %>
7
+ <%
8
+ # Since we do "fair" load balancing to the mongrels, we don't want to share mongrels
9
+ # between haproxy instances otherwise we still end up with requests getting queued behind
10
+ # slow ones.
11
+ mongrel_hosts = rubber_instances.for_role('mongrel').collect { |i| i.name }
12
+ haproxy_hosts = rubber_instances.for_role('haproxy').collect { |i| i.name }
13
+ ports = (rubber_env.mongrel_base_port.to_i ... rubber_env.mongrel_base_port.to_i + rubber_env.mongrel_count.to_i).to_a
14
+ host_count = haproxy_hosts.size
15
+ host_mod = haproxy_hosts.sort.index(rubber_env.host) rescue 0
16
+ ports = ports.find_all {|x| x % host_count == host_mod}
17
+ %>
18
+ <% mongrel_hosts.each do |server| %>
19
+ <% ports.each do |port| %>
20
+ server <%= server %>_<%= port %> <%= server %>:<%= port %> maxconn 1 check
21
+ <% end %>
22
+ <% end %>
23
+
@@ -1,55 +1,31 @@
1
1
  <%
2
- @path = "/etc/nginx/nginx.conf"
3
- @post = "mkdir -p /mnt/nginx/logs"
2
+ @path = "/etc/nginx/rubber/mongrel.conf"
4
3
  %>
5
4
 
6
- user www-data;
7
- worker_processes 10;
8
-
9
- pid /var/run/nginx.pid;
10
-
11
- events
5
+ upstream haproxy_mongrel
12
6
  {
13
- worker_connections 1024;
7
+ <% rubber_instances.for_role('haproxy').each do |ic| %>
8
+ server <%= ic.name %>:<%= rubber_env.haproxy_listen_port %>;
9
+ <% end %>
14
10
  }
15
11
 
16
- http
17
- {
18
- include /etc/nginx/mime.types;
19
- default_type application/octet-stream;
20
-
21
- sendfile on;
22
- tcp_nopush on;
23
- tcp_nodelay off;
24
-
25
- gzip on;
26
- gzip_http_version 1.0;
27
- gzip_comp_level 2;
28
- gzip_proxied any;
29
- gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
30
-
31
- # configure log format like to Apache's "combined" log format
32
- log_format main
33
- '$remote_addr - $remote_user [$time_local] '
34
- '"$request" $status $body_bytes_sent "$http_referer" '
35
- '"$http_user_agent" "$http_cookie"';
36
-
37
- # default log files
38
- error_log /mnt/nginx/logs/error.log notice;
39
- access_log /mnt/nginx/logs/access.log main;
40
-
41
-
42
- upstream mongrel
43
- {
44
- <% proxy_hosts = rubber_instances.for_role('haproxy').each do |ic| %>
45
- server <%= ic.name %>:<%= rubber_env.haproxy_listen_port %>;
46
- <% end %>
47
- }
48
12
 
49
- # This server is setup to serve www.
13
+ <% %w[http https].each do |protocol| %>
14
+
15
+ # This server is setup to serve www over <%= protocol %>.
50
16
  server
51
17
  {
52
- listen 80;
18
+ <% if protocol == 'https' %>
19
+ listen <%= rubber_env.web_ssl_port %>;
20
+ ssl on;
21
+ ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
22
+ ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
23
+ # ssl_certificate <%= RUBBER_ROOT %>/config/snapmylife.com.crt;
24
+ # ssl_certificate_key <%= RUBBER_ROOT %>/config/snapmylife.com.key;
25
+ <% else %>
26
+ listen <%= rubber_env.web_port %>;
27
+ <% end %>
28
+
53
29
  client_max_body_size 10M;
54
30
 
55
31
  server_name <%= rubber_env.domain %>;
@@ -72,6 +48,9 @@ http
72
48
 
73
49
  location /
74
50
  {
51
+ <%# nginx -> rails is http, so this tells rails the source protocol was https %>
52
+ <%= 'proxy_set_header X_FORWARDED_PROTO https;' if protocol == 'https' %>
53
+
75
54
  # needed to forward user's IP address to rails
76
55
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
77
56
 
@@ -111,7 +90,7 @@ http
111
90
 
112
91
  if (!-f $request_filename)
113
92
  {
114
- proxy_pass http://mongrel;
93
+ proxy_pass http://haproxy_mongrel;
115
94
  break;
116
95
  }
117
96
  }
@@ -130,4 +109,5 @@ http
130
109
  root <%= RUBBER_ROOT + "/public" %>;
131
110
  }
132
111
  }
133
- }
112
+
113
+ <% end %>