rubber 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/.travis.yml +2 -4
  2. data/CHANGELOG +98 -0
  3. data/LICENSE +10 -336
  4. data/lib/rubber/cloud/aws.rb +8 -8
  5. data/lib/rubber/commands/cron.rb +1 -1
  6. data/lib/rubber/commands/util.rb +46 -0
  7. data/lib/rubber/encryption.rb +46 -0
  8. data/lib/rubber/environment.rb +24 -5
  9. data/lib/rubber/recipes/rubber.rb +1 -1
  10. data/lib/rubber/recipes/rubber/instances.rb +97 -37
  11. data/lib/rubber/recipes/rubber/setup.rb +9 -4
  12. data/lib/rubber/recipes/rubber/static_ips.rb +3 -2
  13. data/lib/rubber/version.rb +1 -1
  14. data/rubber.gemspec +1 -2
  15. data/templates/apache/config/rubber/rubber-apache.yml +2 -2
  16. data/templates/base/config/deploy.rb +1 -1
  17. data/templates/base/config/rubber/common/crontab +1 -3
  18. data/templates/base/config/rubber/common/gemrc +5 -0
  19. data/templates/base/config/rubber/common/rubber.profile +0 -3
  20. data/templates/base/config/rubber/common/ruby.profile +9 -0
  21. data/templates/base/config/rubber/deploy-setup.rb +45 -65
  22. data/templates/base/config/rubber/rubber-ruby.yml +21 -0
  23. data/templates/base/config/rubber/rubber.yml +8 -3
  24. data/templates/base/script/rubber +7 -3
  25. data/templates/collectd/config/rubber/role/passenger/collectd-passenger.rb.conf +2 -2
  26. data/templates/collectd/config/rubber/role/passenger/passenger-status-sudoers.conf +2 -2
  27. data/templates/complete_unicorn_nginx/config/rubber/rubber-complete.yml +2 -3
  28. data/templates/complete_unicorn_nginx/templates.yml +0 -1
  29. data/templates/elasticsearch/config/rubber/deploy-elasticsearch.rb +1 -1
  30. data/templates/elasticsearch/config/rubber/rubber-elasticsearch.yml +1 -1
  31. data/templates/graphite/config/rubber/deploy-graphite.rb +9 -52
  32. data/templates/graphite/config/rubber/role/graphite_server/carbon.conf +1 -1
  33. data/templates/graphite/config/rubber/role/graphite_server/graphite-collectd-ping.conf +11 -0
  34. data/templates/graphite/config/rubber/role/graphite_server/monit-graphite_server.conf +8 -0
  35. data/templates/graphite/config/rubber/role/graphite_web/graphite_web-upstart.conf +15 -0
  36. data/templates/graphite/config/rubber/role/graphite_web/monit-graphite_web.conf +7 -0
  37. data/templates/graphite/config/rubber/role/graphite_web/uwsgi.ini +16 -0
  38. data/templates/graphite/config/rubber/rubber-graphite.yml +6 -4
  39. data/templates/graphite/templates.yml +2 -0
  40. data/templates/mongrel/config/rubber/deploy-mongrel.rb +1 -1
  41. data/templates/monit/config/rubber/role/mongrel/monit-mongrel.conf +2 -2
  42. data/templates/munin/config/rubber/role/munin/munin-plugins.conf +3 -3
  43. data/templates/munin/config/rubber/role/passenger/munin-passenger-memory.conf +1 -1
  44. data/templates/munin/config/rubber/role/passenger/munin-passenger-sudoers.conf +2 -2
  45. data/templates/munin/config/rubber/role/passenger/munin-passenger.conf +1 -1
  46. data/templates/munin/config/rubber/role/passenger_nginx/munin-passenger-memory.conf +1 -1
  47. data/templates/munin/config/rubber/role/passenger_nginx/munin-passenger-sudoers.conf +2 -2
  48. data/templates/munin/config/rubber/role/passenger_nginx/munin-passenger.conf +1 -1
  49. data/templates/passenger/config/rubber/deploy-passenger.rb +5 -11
  50. data/templates/passenger/config/rubber/role/passenger/passenger-apache-vhost.conf +12 -0
  51. data/templates/passenger/config/rubber/rubber-passenger.yml +3 -3
  52. data/templates/passenger_nginx/config/rubber/role/passenger_nginx/nginx.conf +1 -1
  53. data/templates/passenger_nginx/config/rubber/rubber-passenger_nginx.yml +2 -2
  54. data/templates/postgresql/config/rubber/deploy-postgresql.rb +47 -0
  55. data/templates/redis/config/rubber/rubber-redis.yml +1 -1
  56. data/templates/resque/templates.yml +0 -1
  57. data/templates/sidekiq/config/rubber/deploy-sidekiq.rb +35 -0
  58. data/templates/sidekiq/config/rubber/role/sidekiq/monit-sidekiq.conf +10 -0
  59. data/templates/sidekiq/config/rubber/rubber-sidekiq.yml +2 -0
  60. data/templates/sidekiq/templates.rb +2 -0
  61. data/templates/sidekiq/templates.yml +4 -0
  62. data/templates/solr/config/rubber/common/solr_sunspot.yml +10 -0
  63. data/templates/solr/config/rubber/deploy-solr.rb +78 -0
  64. data/templates/solr/config/rubber/rubber-solr.yml +10 -0
  65. data/templates/solr/templates.yml +3 -0
  66. data/templates/sphinx/config/rubber/deploy-sphinx.rb +4 -4
  67. data/templates/torquebox/config/rubber/deploy-torquebox.rb +16 -4
  68. data/templates/torquebox/config/rubber/role/app/torquebox-apache-vhost.conf +15 -5
  69. data/templates/torquebox/config/rubber/role/torquebox/graylog-logging-module.xml +9 -0
  70. data/templates/torquebox/config/rubber/role/torquebox/standalone-ha.xml +25 -7
  71. data/templates/torquebox/config/rubber/role/torquebox/standalone.conf +2 -2
  72. data/templates/torquebox/config/rubber/rubber-torquebox.yml +6 -3
  73. data/templates/zookeeper/config/rubber/rubber-zookeeper.yml +1 -1
  74. data/test/command_test.rb +7 -5
  75. data/test/commands/cron_test.rb +22 -18
  76. data/test/commands/util_test.rb +40 -0
  77. data/test/encryption_test.rb +59 -0
  78. data/test/environment_test.rb +14 -0
  79. data/test/fixtures/obfuscated/rubber.yml +3 -0
  80. data/test/fixtures/obfuscated/secret.yml +1 -0
  81. metadata +33 -12
  82. data/templates/base/config/rubber/rubber-rvm.yml +0 -42
  83. data/templates/complete_passenger/templates.rb +0 -9
  84. data/templates/complete_passenger_nginx/templates.rb +0 -8
  85. data/templates/complete_unicorn_nginx/config/rubber/role/haproxy/haproxy-unicorn.conf +0 -21
  86. data/templates/complete_unicorn_nginx/templates.rb +0 -8
  87. data/templates/graphite/config/rubber/role/graphite_web/graphite-vhost.conf +0 -62
@@ -0,0 +1,8 @@
1
+ <%
2
+ @path = '/etc/monit/monit.d/monit-graphite_server.conf'
3
+ %>
4
+ check process graphite_server with pidfile <%= rubber_env.graphite_server_pid_file %>
5
+ group graphite-<%= Rubber.env %>
6
+ start program = "/usr/bin/env service graphite-server start"
7
+ stop program = "/usr/bin/env service graphite-server stop"
8
+ if failed host <%= rubber_env.host %> port <%= rubber_env.graphite_server_port %> with timeout 10 seconds for 3 cycles then restart
@@ -0,0 +1,15 @@
1
+ <%
2
+ @path = "/etc/init/graphite-web.conf"
3
+ @backup = false
4
+ %>
5
+
6
+ description "graphite-web uwsgi daemon"
7
+
8
+ start on runlevel [2345]
9
+ stop on runlevel [016]
10
+
11
+ env PID=/var/run/graphite-web.pid
12
+
13
+ expect daemon
14
+
15
+ exec uwsgi --ini /opt/graphite/conf/uwsgi.ini
@@ -0,0 +1,7 @@
1
+ <%
2
+ @path = '/etc/monit/monit.d/monit-graphite-web.conf'
3
+ %>
4
+ check process graphite-web with pidfile /var/run/graphite-web.pid
5
+ group graphite-web-<%= Rubber.env %>
6
+ start program = "/usr/bin/env service graphite-web start"
7
+ stop program = "/usr/bin/env service graphite-web stop"
@@ -0,0 +1,16 @@
1
+ <%
2
+ @path = '/opt/graphite/conf/uwsgi.ini'
3
+ %>
4
+
5
+ [uwsgi]
6
+ http=:<%= rubber_env.graphite_web_port %>
7
+ chdir=/opt/graphite/webapp
8
+ wsgi-file=/opt/graphite/conf/graphite.wsgi
9
+ master=True
10
+ pidfile=/var/run/graphite-web.pid
11
+ processes=4
12
+ die-on-term=True
13
+ vacuum=True
14
+ max-requests=5000
15
+ daemonize=/opt/graphite/storage/log/webapp/webapp.log
16
+ plugins=python,http
@@ -2,12 +2,14 @@ graphite_dir: "/opt/graphite"
2
2
  graphite_server_pid_file: /var/run/graphite-server.pid
3
3
  graphite_server_port: 2003
4
4
  graphite_web_port: 2080
5
+ graphite_carbon_port: 8002
6
+ graphite_storage_dir: /mnt/graphite_storage
5
7
 
6
8
  # uncomment out the repo version to install from given repo version
7
9
  # graphite_repo_version: 426
8
- graphite_whisper_package_url: http://launchpad.net/graphite/0.9/0.9.9/+download/whisper-0.9.9.tar.gz
9
- graphite_carbon_package_url: http://launchpad.net/graphite/0.9/0.9.9/+download/carbon-0.9.9.tar.gz
10
- graphite_web_package_url: http://launchpad.net/graphite/0.9/0.9.9/+download/graphite-web-0.9.9.tar.gz
10
+ graphite_whisper_package_url: https://github.com/downloads/graphite-project/whisper/whisper-0.9.10.tar.gz
11
+ graphite_carbon_package_url: https://github.com/downloads/graphite-project/carbon/carbon-0.9.10.tar.gz
12
+ graphite_web_package_url: https://github.com/downloads/graphite-project/graphite-web/graphite-web-0.9.10.tar.gz
11
13
 
12
14
  web_tools_proxies:
13
15
  graphite:
@@ -17,6 +19,6 @@ web_tools_proxies:
17
19
 
18
20
  roles:
19
21
  graphite_web:
20
- packages: [python-django, python-django-tagging, apache2, libapache2-mod-wsgi, python-cairo, python-memcache, memcached, sqlite3, bzr, zip]
22
+ packages: [python-django, python-django-tagging, python-cairo, python-memcache, memcached, uwsgi, uwsgi-plugin-python, uwsgi-plugin-http, sqlite3, bzr, zip]
21
23
  collectd:
22
24
  packages: [libperl-dev]
@@ -1 +1,3 @@
1
1
  description: The graphite graphing module
2
+ dependent_templates:
3
+ - collectd
@@ -12,7 +12,7 @@ namespace :rubber do
12
12
  rubber.sudo_script 'setup_mongrel_init', <<-ENDSCRIPT
13
13
  mkdir -p /etc/mongrel_cluster
14
14
  rm -f /etc/mongrel_cluster/#{application}-#{Rubber.env}.yml && ln -s /mnt/#{application}-#{Rubber.env}/current/config/mongrel_cluster.yml /etc/mongrel_cluster/#{application}-#{Rubber.env}.yml
15
- find #{rubber_env.rvm_version ? "$(rvm gemdir)" : "/usr/lib/ruby/gems"} -path "*/resources/mongrel_cluster" -exec cp {} /etc/init.d/ \\;
15
+ find #{rubber_env.ruby_path} -path "*/resources/mongrel_cluster" -exec cp {} /etc/init.d/ \\;
16
16
  chmod +x /etc/init.d/mongrel_cluster
17
17
  update-rc.d -f mongrel_cluster remove
18
18
  update-rc.d mongrel_cluster defaults 99 00
@@ -8,12 +8,12 @@
8
8
  <% pidfile = "#{Rubber.root}/tmp/pids/mongrel.#{port}.pid" %>
9
9
  check process mongrel-<%= port %> with pidfile <%= pidfile %>
10
10
  group mongrel-<%= Rubber.env %>
11
- start program = "/bin/sh -c 'cd <%= Rubber.root %> && PATH=<%= rubber_env.ruby_prefix %>/bin:/usr/local/bin:$PATH && mongrel_rails cluster::start --clean --only <%= port %>'"
11
+ start program = "/bin/sh -c 'cd <%= Rubber.root %> && PATH=/usr/local/bin:$PATH && mongrel_rails cluster::start --clean --only <%= port %>'"
12
12
  <%
13
13
  # Stop gracefully - monit waits for stop to complete (since below process exits immediately, it must
14
14
  # wait for pid to disappear) before trying to start
15
15
  %>
16
- stop program = "/bin/sh -c 'cd <%= Rubber.root %> && PATH=<%= rubber_env.ruby_prefix %>/bin:/usr/local/bin:$PATH && mongrel_rails cluster::stop --clean --only <%= port %> && sleep 30 && mongrel_rails cluster::stop --clean --force --only <%= port %>'"
16
+ stop program = "/bin/sh -c 'cd <%= Rubber.root %> && PATH=/usr/local/bin:$PATH && mongrel_rails cluster::stop --clean --only <%= port %> && sleep 30 && mongrel_rails cluster::stop --clean --force --only <%= port %>'"
17
17
  if totalmem > 200.0 MB for 3 cycles then restart
18
18
  <%# monit needs to test on same same interface that mongrel is listening on (see mongrel_cluster.yml) %>
19
19
  if failed host <%= rubber_env.host %> port <%= port %> protocol http with timeout 10 seconds for 10 cycles then restart
@@ -2,10 +2,10 @@
2
2
  @path = '/etc/munin/plugin-conf.d/rubber'
3
3
  %>
4
4
 
5
- # munin-node clears out enviroment variables, so we need to add these in
6
- # to make sure we are running the correct ruby (rvm env vars, plus paths)
5
+ # munin-node clears out environment variables, so we need to add these in
6
+ # to make sure we are running the correct ruby (ruby env vars, plus paths)
7
7
  [*]
8
- <%- ENV.select {|k, v| k =~ /rvm|ruby|bundler|gem|path/i; v != "" }.each do |k, v| -%>
8
+ <%- ENV.select {|k, v| k =~ /ruby|bundler|gem|path/i; v != "" }.each do |k, v| -%>
9
9
  env.<%= k %> <%= v %>
10
10
  <%- end -%>
11
11
  env.RUBYOPT rubygems
@@ -18,7 +18,7 @@ END
18
18
  end
19
19
 
20
20
  def output_values
21
- status = `rvm exec sudo <%= rubber_env.rvm_gem_home %>/bin/passenger-memory-stats | tail -1`
21
+ status = `sudo <%= rubber_env.ruby_path %>/bin/passenger-memory-stats | tail -1`
22
22
  unless $?.success?
23
23
  $stderr.puts "failed executing passenger-memory-stats"
24
24
  exit 1
@@ -4,5 +4,5 @@
4
4
  %>
5
5
  Defaults env_keep = GEM_PATH
6
6
 
7
- nobody ALL=(ALL) NOPASSWD: <%= rubber_env.rvm_gem_home %>/bin/passenger-status
8
- nobody ALL=(ALL) NOPASSWD: <%= rubber_env.rvm_gem_home %>/bin/passenger-memory-stats
7
+ nobody ALL=(ALL) NOPASSWD: <%= rubber_env.ruby_path %>/bin/passenger-status
8
+ nobody ALL=(ALL) NOPASSWD: <%= rubber_env.ruby_path %>/bin/passenger-memory-stats
@@ -21,7 +21,7 @@ END
21
21
  end
22
22
 
23
23
  def output_values
24
- status = `rvm exec sudo <%= rubber_env.rvm_gem_home %>/bin/passenger-status`
24
+ status = `sudo <%= rubber_env.ruby_path %>/bin/passenger-status`
25
25
  unless $?.success?
26
26
  $stderr.puts "failed executing passenger-status"
27
27
  exit 1
@@ -18,7 +18,7 @@ END
18
18
  end
19
19
 
20
20
  def output_values
21
- status = `rvm exec sudo <%= rubber_env.rvm_gem_home %>/bin/passenger-memory-stats | tail -1`
21
+ status = `sudo <%= rubber_env.ruby_path %>/bin/passenger-memory-stats | tail -1`
22
22
  unless $?.success?
23
23
  $stderr.puts "failed executing passenger-memory-stats"
24
24
  exit 1
@@ -4,5 +4,5 @@
4
4
  %>
5
5
  Defaults env_keep = GEM_PATH
6
6
 
7
- nobody ALL=(ALL) NOPASSWD: <%= rubber_env.rvm_gem_home %>/bin/passenger-status
8
- nobody ALL=(ALL) NOPASSWD: <%= rubber_env.rvm_gem_home %>/bin/passenger-memory-stats
7
+ nobody ALL=(ALL) NOPASSWD: <%= rubber_env.ruby_path %>/bin/passenger-status
8
+ nobody ALL=(ALL) NOPASSWD: <%= rubber_env.ruby_path %>/bin/passenger-memory-stats
@@ -21,7 +21,7 @@ END
21
21
  end
22
22
 
23
23
  def output_values
24
- status = `rvm exec sudo <%= rubber_env.rvm_gem_home %>/bin/passenger-status`
24
+ status = `sudo <%= rubber_env.ruby_path %>/bin/passenger-status`
25
25
  unless $?.success?
26
26
  $stderr.puts "failed executing passenger-status"
27
27
  exit 1
@@ -2,21 +2,16 @@
2
2
  namespace :rubber do
3
3
 
4
4
  namespace :passenger do
5
-
5
+
6
6
  rubber.allow_optional_tasks(self)
7
-
7
+
8
8
  after "rubber:install_gems", "rubber:passenger:custom_install"
9
-
9
+
10
10
  task :custom_install, :roles => :passenger do
11
11
  rubber.sudo_script 'install_passenger', <<-ENDSCRIPT
12
- # can't use passenger_lib from rubber here as it only evaluates correctly
13
- # when variable interpolation of rvm_gem_home is run remotely, and since we
14
- # are in cap, we run the interpolation locally
15
- #
16
- passenger_lib=$(find /usr/local/rvm/gems/`rvm current` -path "*/passenger-#{rubber_env.passenger_version}/*/mod_passenger.so" 2> /dev/null)
12
+ passenger_lib=$(find #{rubber_env.ruby_path} -path "*/passenger-#{rubber_env.passenger_version}/*/mod_passenger.so" 2> /dev/null)
17
13
  if [[ -z $passenger_lib ]]; then
18
14
  echo -en "\n\n\n\n" | passenger-install-apache2-module
19
- rvm #{rubber_env.rvm_ruby} --passenger
20
15
  fi
21
16
  ENDSCRIPT
22
17
  end
@@ -58,8 +53,7 @@ namespace :rubber do
58
53
  rsudo "while ! curl -s -f http://localhost:$CAPISTRANO:VAR$/ &> /dev/null; do echo .; done", opts
59
54
  rsudo "touch #{current_path}/public/httpchk.txt"
60
55
  end
61
-
62
-
56
+
63
57
  # passenger depends on apache for start/stop/restart, just need these defined
64
58
  # as apache hooks into standard deploy lifecycle
65
59
 
@@ -1,6 +1,11 @@
1
1
  <%
2
2
  @path = "/etc/apache2/sites-available/#{rubber_env.app_name}-passenger"
3
3
  @post = "a2enmod rewrite && a2enmod ssl && a2enmod expires && a2enmod xsendfile && a2ensite #{rubber_env.app_name}-passenger"
4
+
5
+ sidekiq_gem_path = if rubber_instances.for_role('sidekiq').any?
6
+ require 'sidekiq'
7
+ `find /mnt/#{rubber_env.app_name}-#{RUBBER_ENV}/shared/bundle -name sidekiq-#{Sidekiq::VERSION}`.strip
8
+ end
4
9
  %>
5
10
 
6
11
  <% [rubber_env.passenger_listen_port, rubber_env.passenger_listen_ssl_port].each do |port| %>
@@ -25,6 +30,10 @@ Listen <%= port %>
25
30
 
26
31
  XSendFile on
27
32
 
33
+ <% if rubber_instances.for_role('sidekiq').any? %>
34
+ XSendFilePath <%= sidekiq_gem_path %>/web/assets
35
+ <% end %>
36
+
28
37
  RewriteEngine On
29
38
  RewriteCond %{HTTP_HOST} ^<%= rubber_env.domain %>$
30
39
  RewriteRule ^(.*)$ http://www.<%= rubber_env.domain %>$1 [R,L]
@@ -47,6 +56,9 @@ Listen <%= port %>
47
56
  # Cache the resource even if SSL is in use.
48
57
  Header merge Cache-Control public
49
58
 
59
+ # Remove any cookies set with the request so we avoid them being cached in a CDN.
60
+ Header unset Set-Cookie
61
+
50
62
  SetEnv no-gzip
51
63
  </LocationMatch>
52
64
 
@@ -1,6 +1,6 @@
1
- passenger_version: 3.0.15
2
- passenger_root: "#{rvm_gem_home}/gems/passenger-#{passenger_version}"
3
- passenger_ruby: "#{rvm_prefix}/wrappers/#{`bash -l -c 'rvm strings #{rvm_ruby}'`.strip}/ruby"
1
+ passenger_version: 3.0.19
2
+ passenger_root: "#{`bash -l -c 'find #{ruby_path} -name passenger-#{passenger_version}'`.strip}"
3
+ passenger_ruby: "#{ruby_path}/bin/ruby"
4
4
  passenger_lib: "#{passenger_root}/ext/apache2/mod_passenger.so"
5
5
  passenger_listen_port: 7000
6
6
  passenger_listen_ssl_port: 7001
@@ -46,7 +46,7 @@ http
46
46
 
47
47
  passenger_root <%= rubber_env.passenger_root %>;
48
48
  passenger_ruby <%= rubber_env.passenger_ruby %>;
49
-
49
+
50
50
  passenger_max_pool_size <%= rubber_env.max_app_connections %>;
51
51
  passenger_min_instances <%= rubber_env.max_app_connections %>;
52
52
  passenger_max_instances_per_app 0;
@@ -1,7 +1,7 @@
1
1
  passenger_version: 3.0.11
2
2
  nginx_version: 1.0.11
3
- passenger_root: "#{rvm_gem_home}/gems/passenger-#{passenger_version}"
4
- passenger_ruby: "#{rvm_prefix}/wrappers/#{`bash -l -c 'rvm strings #{rvm_ruby}'`.strip}/ruby"
3
+ passenger_root: "#{`bash -l -c 'find #{ruby_path} -name passenger-#{passenger_version}'`.strip}"
4
+ passenger_ruby: "#{ruby_path}/bin/ruby"
5
5
  passenger_lib: "#{passenger_root}/ext/nginx"
6
6
  passenger_listen_port: 7000
7
7
  passenger_listen_ssl_port: 7001
@@ -112,6 +112,53 @@ namespace :rubber do
112
112
  ENDSCRIPT
113
113
  end
114
114
 
115
+ desc <<-DESC
116
+ Promotes a slave instance to master
117
+ DESC
118
+ task :promote_slave do
119
+ master_alias = get_env('MASTER', "Master alias (e.g. db01)", true)
120
+ slave_alias = get_env('SLAVE', "Slave alias (e.g. db02)", true)
121
+
122
+ # remove the master instance so rubber doesn't try to deploy to it
123
+ # Stays running so needs to be manually deleted
124
+ master_instance = rubber_instances.remove(master_alias)
125
+ fatal "Master Instance does not exist: #{master_alias}" unless master_instance
126
+
127
+ slave_instance = rubber_instances[slave_alias]
128
+ fatal "Slave Instance does not exist: #{slave_alias}" unless slave_instance
129
+
130
+ # remove all db roles from slave
131
+ slave_instance.roles.delete_if {|ir| ir.name =~ /db|postgresql/ }
132
+
133
+ # add in master db roles to slave
134
+ new_roles = [Rubber::Configuration::RoleItem.parse("postgresql_master")]
135
+ new_roles = Rubber::Configuration::RoleItem.expand_role_dependencies(new_roles, get_role_dependencies)
136
+ slave_instance.roles = (slave_instance.roles + new_roles).uniq
137
+
138
+ rubber_instances.save()
139
+
140
+ begin
141
+ Timeout::timeout(10) do
142
+ logger.info "Stopping server on original master #{master_alias}"
143
+ rsudo "service monit stop || true", :hosts => master_instance.full_name
144
+ rsudo "service postgresql stop || true", :hosts => master_instance.full_name
145
+ end
146
+ rescue StandardError
147
+ logger.info "Failed to connect to original master, promoting slave anyway"
148
+ end
149
+
150
+ logger.info "Triggering slave promotion on new master #{slave_alias}"
151
+ rsudo "touch #{rubber_env.postgresql_data_dir}/trigger_file", :hosts => slave_instance.full_name
152
+
153
+ logger.info "The master instance has been removed from instances, but remains running:"
154
+ logger.info "#{master_alias}, #{master_instance.instance_id}, #{master_instance.external_ip}"
155
+ logger.info ''
156
+ logger.info "Roles for #{slave_alias} are now:"
157
+ logger.info slave_instance.roles.inspect
158
+ logger.info ''
159
+ logger.info "Promotion complete, you should commit the instance file and deploy"
160
+ end
161
+
115
162
  desc <<-DESC
116
163
  Starts the postgresql daemons
117
164
  DESC
@@ -1,4 +1,4 @@
1
- redis_server_version: 2.4.16
1
+ redis_server_version: 2.4.18
2
2
  redis_server_pid_file: /var/run/redis-server.pid
3
3
  redis_server_conf_file: /etc/redis.conf
4
4
  redis_server_log_file: /var/log/redis-server.log
@@ -1,4 +1,3 @@
1
1
  description: The resque background queue system
2
2
  dependent_templates:
3
3
  - redis
4
- skip_unknown_roles: true
@@ -0,0 +1,35 @@
1
+ namespace :rubber do
2
+ namespace :sidekiq do
3
+
4
+ rubber.allow_optional_tasks(self)
5
+
6
+ before "deploy", "rubber:sidekiq:quiet"
7
+ after "deploy:stop", "rubber:sidekiq:stop"
8
+ after "deploy:start", "rubber:sidekiq:start"
9
+ after "deploy:restart", "rubber:sidekiq:restart"
10
+
11
+ desc "Quiet sidekiq (stop accepting new work)"
12
+ task :quiet, :roles => :sidekiq do
13
+ rsudo "cd #{current_path} && if [ -f #{current_path}/tmp/pids/sidekiq.pid ]; then bundle exec sidekiqctl quiet #{current_path}/tmp/pids/sidekiq.pid ; fi", :as => rubber_env.app_user
14
+ end
15
+
16
+ desc "Stop sidekiq"
17
+ task :stop, :roles => :sidekiq do
18
+ # Allow workers up to 60 seconds to finish their processing.
19
+ rsudo "cd #{current_path} && if [ -f #{current_path}/tmp/pids/sidekiq.pid ]; then bundle exec sidekiqctl stop #{current_path}/tmp/pids/sidekiq.pid 60 ; fi", :as => rubber_env.app_user
20
+ end
21
+
22
+ desc "Start sidekiq"
23
+ task :start, :roles => :sidekiq do
24
+ rsudo "cd #{current_path} ; nohup bundle exec sidekiq -e #{Rubber.env} -C #{current_path}/config/sidekiq.yml -P #{current_path}/tmp/pids/sidekiq.pid >> #{current_path}/log/sidekiq.log 2>&1 &", :pty => false, :as => rubber_env.app_user
25
+ sleep 45 # Give the workers some time to start up before moving on so monit doesn't try to start as well.
26
+ end
27
+
28
+ desc "Restart sidekiq"
29
+ task :restart, :roles => :sidekiq do
30
+ stop
31
+ start
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ <%
2
+ @path = '/etc/monit/monit.d/monit-sidekiq.conf'
3
+ start_program = "/usr/bin/sudo -H -u #{rubber_env.app_user} /bin/bash -l -c 'cd #{Rubber.root} ; nohup ./bin/sidekiq -e #{Rubber.env} -C #{Rubber.root}/config/sidekiq.yml -P #{Rubber.root}/tmp/pids/sidekiq.pid >> #{Rubber.root}/log/sidekiq.log 2>&1 &'"
4
+ stop_program = "/usr/bin/sudo -H -u #{rubber_env.app_user} /bin/bash -l -c 'cd #{Rubber.root} && if [ -f #{Rubber.root}/tmp/pids/sidekiq.pid ]; then ./bin/sidekiqctl stop #{Rubber.root}/tmp/pids/sidekiq.pid 60 ; fi'"
5
+ %>
6
+
7
+ check process sidekiq with pidfile <%= Rubber.root %>/tmp/pids/sidekiq.pid
8
+ group selenium_grid_hub
9
+ start program = "<%= start_program %>"
10
+ stop program = "<%= stop_program %>"
@@ -0,0 +1,2 @@
1
+ role_dependencies:
2
+ background_worker: [sidekiq]
@@ -0,0 +1,2 @@
1
+ append_to_file 'Gemfile', "gem 'sidekiq'\n" if Rubber::Util::is_bundler?
2
+ append_to_file 'Gemfile', "gem 'slim'\n" if Rubber::Util::is_bundler?
@@ -0,0 +1,4 @@
1
+ description: The sidekiq background queue system
2
+ dependent_templates:
3
+ - redis
4
+ skip_unknown_roles: true
@@ -0,0 +1,10 @@
1
+ <%
2
+ @path = "#{Rubber.root}/config/sunspot.yml"
3
+ @additive = ["#prod_start", "#prod_end"]
4
+ %> <% rubber_instances.for_role('solr').each do |ic| %>
5
+ production:
6
+ solr:
7
+ hostname: <%= ic.external_host %>
8
+ port: 8080
9
+ log_level: WARNING
10
+ <% end %>
@@ -0,0 +1,78 @@
1
+ # installs, starts and stops solr
2
+ #
3
+ # * installation is ubuntu specific
4
+ # * start and stop tasks are using the thinking sphinx plugin
5
+
6
+ namespace :rubber do
7
+
8
+ namespace :solr do
9
+
10
+ rubber.allow_optional_tasks(self)
11
+
12
+ after "rubber:install_packages", "rubber:solr:custom_install"
13
+
14
+ desc "custom installing java and solr"
15
+ task :custom_install, :roles => :solr do
16
+
17
+ upload rubber_env.jdk_path, "/tmp/#{rubber_env.jdk}"
18
+ upload rubber_env.solr_xml_path, "/tmp/#{rubber_env.solr_xml}"
19
+ upload rubber_env.tarz_config_files, "/tmp/solr_conf.tar.gz"
20
+ rubber.sudo_script 'install_java_solr', <<-ENDSCRIPT
21
+ if [ ! -d "/usr/lib/jvm/jdk1.7" ]; then
22
+ echo 'installing oracle java'
23
+ tar -zxf /tmp/#{rubber_env.jdk} -C /tmp
24
+ sudo mkdir -p /usr/lib/jvm/jdk1.7
25
+ mv -f /tmp/jdk1.7.0_10/* /usr/lib/jvm/jdk1.7/
26
+
27
+ echo 'updating java alterlative'
28
+ update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7/bin/java" 1
29
+ update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7/bin/javac" 1
30
+ update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7/bin/javaws" 1
31
+
32
+ echo 'installing tomcat'
33
+ curl -o /tmp/apache-tomcat-7.0.34.tar.gz http://ftp.heanet.ie/mirrors/www.apache.org/dist/tomcat/tomcat-7/v7.0.34/bin/apache-tomcat-7.0.34.tar.gz
34
+ tar -zxf /tmp/apache-tomcat-7.0.34.tar.gz -C #{rubber_env.tomcat_dest_folder}
35
+ rm /tmp/apache-tomcat-7.0.34.tar.gz
36
+
37
+ echo 'installing solr'
38
+ curl -o /tmp/apache-solr-4.0.0.tgz http://ftp.heanet.ie/mirrors/www.apache.org/dist/lucene/solr/4.0.0/apache-solr-4.0.0.tgz
39
+ tar -zxf /tmp/apache-solr-4.0.0.tgz -C /tmp
40
+ cp /tmp/apache-solr-4.0.0/dist/apache-solr-4.0.0.war /mnt/apache-tomcat-7.0.34/webapps/solr.war
41
+ rm -fr /tmp/apache-solr-4.0.0*
42
+
43
+ echo 'setting up solr'
44
+ mkdir -p #{rubber_env.solr_home_dest_foler}/solr/data
45
+ mkdir -p #{rubber_env.solr_home_dest_foler}/solr/#{rubber_env.core_name}
46
+ tar -zxf /tmp/solr_conf.tar.gz -C /mnt/solr/#{rubber_env.core_name}
47
+ mv /tmp/#{rubber_env.solr_xml} #{rubber_env.solr_home_dest_foler}/solr
48
+ rm /tmp/solr_conf.tar.gz
49
+ fi
50
+ ENDSCRIPT
51
+ end
52
+
53
+
54
+ def set_java_opts
55
+ "export JAVA_OPTS='-server -Xmx#{rubber_env.Xmx} -Dsolr.data.dir=#{rubber_env.solr_home_dest_foler}/solr/data -Dsolr.solr.home=#{rubber_env.solr_home_dest_foler}/solr'"
56
+ end
57
+
58
+ desc "start solr"
59
+ task :start_solr, :roles => :solr do
60
+ rubber.sudo_script 'start_solr', <<-ENDSCRIPT
61
+ echo 'starting tomcat'
62
+ #{set_java_opts}
63
+ nohup #{rubber_env.tomcat_dest_folder}/apache-tomcat-7.0.34/bin/startup.sh &
64
+ sleep 5
65
+ ENDSCRIPT
66
+ end
67
+
68
+ desc "stop solr"
69
+ task :stop_solr, :roles => :solr do
70
+ rubber.sudo_script 'stop_solr', <<-ENDSCRIPT
71
+ echo 'stoping tomcat'
72
+ #{set_java_opts}
73
+ #{rubber_env.tomcat_dest_folder}/apache-tomcat-7.0.34/bin/shutdown.sh
74
+ ENDSCRIPT
75
+ end
76
+ end
77
+
78
+ end