rubber 2.6.5 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG +37 -0
- data/lib/rubber/cloud/vsphere.rb +4 -0
- data/lib/rubber/generator.rb +37 -19
- data/lib/rubber/recipes/rubber/security_groups.rb +1 -1
- data/lib/rubber/recipes/rubber/volumes.rb +1 -1
- data/lib/rubber/version.rb +1 -1
- data/templates/delayed_job/config/rubber/deploy-delayed_job.rb +44 -0
- data/templates/delayed_job/config/rubber/role/delayed_job/monit-delayed_job.conf +18 -0
- data/templates/delayed_job/config/rubber/rubber-delayed_job.yml +1 -0
- data/templates/delayed_job/templates.yml +1 -0
- data/templates/discourse/config/rubber/deploy-discourse.rb +16 -0
- data/templates/discourse/config/rubber/role/nginx/nginx.conf +43 -0
- data/templates/discourse/config/rubber/role/nginx/unicorn_nginx.conf +102 -0
- data/templates/discourse/config/rubber/role/unicorn/unicorn.rb +99 -0
- data/templates/discourse/config/rubber/rubber-discourse.yml +3 -0
- data/templates/discourse/templates.yml +5 -0
- data/templates/elasticsearch/config/rubber/deploy-elasticsearch.rb +7 -7
- data/templates/elasticsearch/config/rubber/role/elasticsearch/elasticsearch-default.conf +47 -0
- data/templates/elasticsearch/config/rubber/role/elasticsearch/elasticsearch.yml +49 -30
- data/templates/elasticsearch/config/rubber/role/elasticsearch/logging.yml +14 -3
- data/templates/elasticsearch/config/rubber/role/elasticsearch/monit-elasticsearch.conf +8 -0
- data/templates/elasticsearch/config/rubber/rubber-elasticsearch.yml +1 -4
- data/templates/ffmpeg/config/rubber/deploy-ffmpeg.rb +13 -0
- data/templates/ffmpeg/config/rubber/rubber-ffmpeg.yml +5 -0
- data/templates/ffmpeg/templates.yml +1 -0
- data/templates/graylog/config/rubber/deploy-graylog.rb +17 -20
- data/templates/graylog/config/rubber/role/graylog_server/graylog2.conf +157 -43
- data/templates/graylog/config/rubber/role/graylog_server/monit-graylog_server.conf +8 -0
- data/templates/graylog/config/rubber/role/graylog_web/graylog2-web-interface.conf +19 -0
- data/templates/graylog/config/rubber/role/graylog_web/graylog_web-upstart.conf +1 -1
- data/templates/graylog/config/rubber/role/graylog_web/monit-graylog_web.conf +8 -0
- data/templates/graylog/config/rubber/rubber-graylog.yml +5 -12
- data/templates/graylog/templates.rb +13 -5
- data/templates/memcached/config/rubber/deploy-memcached.rb +16 -0
- data/templates/memcached/config/rubber/role/memcached/dalli.rb +20 -0
- data/templates/memcached/config/rubber/role/memcached/memcached.conf +17 -8
- data/templates/memcached/config/rubber/rubber-memcached.yml +25 -1
- data/templates/monit/config/rubber/role/memcached/monit-memcached.conf +9 -0
- data/templates/monit/config/rubber/role/mongodb/monit-mongodb.conf +1 -0
- data/templates/mysql/config/rubber/deploy-mysql.rb +1 -2
- data/templates/newrelic/config/rubber/deploy-newrelic.rb +49 -0
- data/templates/newrelic/config/rubber/role/newrelic/monit-newrelic.conf +9 -0
- data/templates/newrelic/config/rubber/rubber-newrelic.yml +5 -0
- data/templates/newrelic/templates.yml +1 -0
- data/templates/passenger_nginx/config/rubber/deploy-passenger_nginx.rb +7 -4
- data/templates/passenger_nginx/config/rubber/rubber-passenger_nginx.yml +1 -0
- data/templates/redis/config/rubber/role/redis/redis.conf +120 -16
- data/templates/redis/config/rubber/rubber-redis.yml +1 -1
- data/templates/solr/config/rubber/deploy-solr.rb +8 -8
- data/templates/solr/config/rubber/rubber-solr.yml +6 -6
- data/templates/solr/templates.yml +1 -3
- data/templates/solr_sunspot/config/rubber/common/solr_sunspot.yml +10 -0
- data/templates/solr_sunspot/config/rubber/deploy-solr_sunspot.rb +30 -0
- data/templates/solr_sunspot/config/rubber/rubber-solr_sunspot.yml +5 -0
- data/templates/solr_sunspot/templates.yml +1 -0
- data/templates/unicorn/config/rubber/deploy-unicorn.rb +16 -11
- data/templates/unicorn/config/rubber/role/unicorn/unicorn +91 -0
- data/test/generator_test.rb +54 -0
- data/test/test_helper.rb +2 -0
- metadata +31 -11
- data/templates/elasticsearch/config/rubber/role/elasticsearch/elasticsearch-upstart.conf +0 -23
- data/templates/graylog/config/initializers/graylog.rb +0 -53
- data/templates/graylog/config/rubber/role/graylog_web/crontab +0 -9
- data/templates/graylog/config/rubber/role/graylog_web/email.yml +0 -16
- data/templates/graylog/config/rubber/role/graylog_web/general.yml +0 -27
- data/templates/graylog/config/rubber/role/graylog_web/mongoid.yml +0 -28
- data/templates/memcached/config/memcached.yml +0 -28
- data/templates/memcached/config/rubber/common/memcached.yml +0 -14
- data/templates/unicorn/config/rubber/role/unicorn/unicorn-upstart.conf +0 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8aebd49d6b6f4dc7f30e6ae01e61314f3237e407
|
|
4
|
+
data.tar.gz: 647342efba82bb0a7e224c90334a22fd19d73336
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a75e1ff0966eef3fd8589b75056b4a78d11e86435a105e72aa2ee4cc2a24258f21e7da5f4d68ff49909d0b9a7985b1cd0b8da3fd568b90c74fe1e8eccb6c7004
|
|
7
|
+
data.tar.gz: 1e309a5b087198178f0aa8e28657947d078f727c205791d00b3e2efc4beab543017703ee502a1174e9b80af10b88defdb7e1790aae26de220a876d4ad95b4987
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
2.7.0 (02/03/2014)
|
|
2
|
+
|
|
3
|
+
New Features:
|
|
4
|
+
============
|
|
5
|
+
|
|
6
|
+
[core] Added a new @delayed_post option to template preambles to defer executing a command until all templates have been processed. <41cae48>
|
|
7
|
+
[delay_job] Added a new Delayed::Job role. <c7e33f5>
|
|
8
|
+
[discourse] Added a new Discourse role that will take care of deploying the Discourse forum software and dependencies. <f01eeac>
|
|
9
|
+
[ffmpeg] Added a new ffmpeg role. <23ba011>
|
|
10
|
+
[newrelic] Added a new role for setting up the NewRelic system daemons. <7bc89ce>
|
|
11
|
+
|
|
12
|
+
Improvements:
|
|
13
|
+
============
|
|
14
|
+
|
|
15
|
+
[core] Force shut down vSphere VMs when destroying an instance so the process isn't blocked if the machine doesn't shut down gracefully. <12bf770>
|
|
16
|
+
[elasticsearch] Upgraded ElasticSearch from 0.19.12 to 0.90.10 and switched to the official deb packages. <a399316, 804bd1f, 4ca29e2>
|
|
17
|
+
[graylog] Upgraded from graylog 0.9.6p1 to 0.20.0-rc1.1 <3476003, 4ca29e2>
|
|
18
|
+
[memcached] Added a monit template. <87763e9>
|
|
19
|
+
[memcached] Allow specifying the location of the PID file. <31bc9fb>
|
|
20
|
+
[memcached] Major overhaul of the memcached template to modernize it. <8757cf8, 4307270, 8cebb56, ae8d89a>
|
|
21
|
+
[mongodb] Monit will restart mongodb if the PID file doesn't exist. <7a57c3e>
|
|
22
|
+
[redis] Upgraded from redis 2.6.16 to 2.8.4 <3877205, 644e6ee>
|
|
23
|
+
[solr] Major overhaul of the solr template to modernize it. <a45046d, 2fc4779, 02e04b0, 676256d>
|
|
24
|
+
|
|
25
|
+
Bug Fixes:
|
|
26
|
+
=========
|
|
27
|
+
|
|
28
|
+
[core] Fixed issue with calling cap rubber:setup_security_groups on multiple hosts. <bb17621>
|
|
29
|
+
[core] Fixed volume creation on non-EC2 providers. <c49df54>
|
|
30
|
+
[elasticsearch] Remove the elasticsearch-head plugin before attempting to reinstall it. <6438b68>
|
|
31
|
+
[mysql] Delete all blank users initially to prevent issues with using a host value of '%'. <e75974a>
|
|
32
|
+
[passenger_nginx] Added missing 'nginx_log_dir' setting to rubber-passenger_nginx.yml. <e6c3cdf>
|
|
33
|
+
[passenger_nginx] Rebuild Passenger/Nginx when Ruby version changes. <fbb1e54>
|
|
34
|
+
[solr] Fixed some typos in the Solr configuration. <a45046d>
|
|
35
|
+
[unicorn] Fixed unicorn process management script. <c56a93c>
|
|
36
|
+
|
|
37
|
+
|
|
1
38
|
2.6.5 (01/07/2014)
|
|
2
39
|
|
|
3
40
|
Bug Fixes:
|
data/lib/rubber/cloud/vsphere.rb
CHANGED
data/lib/rubber/generator.rb
CHANGED
|
@@ -21,6 +21,7 @@ module Rubber
|
|
|
21
21
|
@roles = roles.to_a.reverse #First roles take precedence
|
|
22
22
|
@host = host || 'no_host'
|
|
23
23
|
@options=options
|
|
24
|
+
@delayed_post_commands = []
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
def run
|
|
@@ -47,6 +48,33 @@ module Rubber
|
|
|
47
48
|
end
|
|
48
49
|
end
|
|
49
50
|
end
|
|
51
|
+
|
|
52
|
+
@delayed_post_commands = @delayed_post_commands.uniq
|
|
53
|
+
if @delayed_post_commands.size > 0
|
|
54
|
+
Rubber.logger.info("Running delayed post commands")
|
|
55
|
+
|
|
56
|
+
@delayed_post_commands.each do |delayed_post_command|
|
|
57
|
+
run_post_command(delayed_post_command)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def run_post_command(cmd)
|
|
63
|
+
if fake_root
|
|
64
|
+
Rubber.logger.info("Not running post command as a fake root was given: #{cmd}")
|
|
65
|
+
elsif no_post
|
|
66
|
+
Rubber.logger.info("Not running post command as no post specified: #{cmd}")
|
|
67
|
+
else
|
|
68
|
+
# this lets us abort a script if a command in the middle of it errors out
|
|
69
|
+
# stop_on_error_cmd = "function error_exit { exit 99; }; trap error_exit ERR"
|
|
70
|
+
cmd_with_error_handler = stop_on_error_cmd ? "#{stop_on_error_cmd}\n#{cmd}" : cmd
|
|
71
|
+
|
|
72
|
+
Rubber.logger.info{"Transformation executing post config command: #{cmd}"}
|
|
73
|
+
Rubber.logger.info `#{cmd_with_error_handler}`
|
|
74
|
+
if $?.exitstatus != 0
|
|
75
|
+
raise "Post command failed execution: #{cmd_with_error_handler}"
|
|
76
|
+
end
|
|
77
|
+
end
|
|
50
78
|
end
|
|
51
79
|
|
|
52
80
|
# Transforms the ERB template given in srcfile and writes the result to
|
|
@@ -154,25 +182,13 @@ module Rubber
|
|
|
154
182
|
|
|
155
183
|
# Run post transform command if needed
|
|
156
184
|
if config.post
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
# stop_on_error_cmd = "function error_exit { exit 99; }; trap error_exit ERR"
|
|
165
|
-
config.post = "#{stop_on_error_cmd}\n#{config.post}" if stop_on_error_cmd
|
|
166
|
-
|
|
167
|
-
Rubber.logger.info{"Transformation executing post config command: #{config.post}"}
|
|
168
|
-
Rubber.logger.info `#{config.post}`
|
|
169
|
-
if $?.exitstatus != 0
|
|
170
|
-
raise "Post command failed execution: #{config.post}"
|
|
171
|
-
end
|
|
172
|
-
else
|
|
173
|
-
Rubber.logger.info("Nothing to do, not running post command")
|
|
174
|
-
end
|
|
175
|
-
end
|
|
185
|
+
run_post_command(config.post)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Schedule delayed_post transform command if needed
|
|
189
|
+
if config.delayed_post
|
|
190
|
+
Rubber.logger.info "Scheduling delayed_post: #{config.delayed_post}"
|
|
191
|
+
@delayed_post_commands << config.delayed_post
|
|
176
192
|
end
|
|
177
193
|
end
|
|
178
194
|
end
|
|
@@ -191,6 +207,8 @@ module Rubber
|
|
|
191
207
|
attr_accessor :write_cmd
|
|
192
208
|
# The command to run after generating the config file if it has changed
|
|
193
209
|
attr_accessor :post
|
|
210
|
+
# The command to run after generating _all_ config files if this file has changed. Commands duplicated from multiple files are only run once
|
|
211
|
+
attr_accessor :delayed_post
|
|
194
212
|
# The owner the output file should have, e.g. "root"
|
|
195
213
|
attr_accessor :owner
|
|
196
214
|
# The group the output file should have, e.g. "system"
|
|
@@ -8,7 +8,7 @@ namespace :rubber do
|
|
|
8
8
|
required_task :setup_security_groups do
|
|
9
9
|
servers = find_servers_for_task(current_task)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
servers.collect(&:host).each{ |host| cloud.setup_security_groups(host) }
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
desc <<-DESC
|
|
@@ -132,7 +132,7 @@ namespace :rubber do
|
|
|
132
132
|
fi
|
|
133
133
|
mv /etc/fstab /etc/fstab.bak
|
|
134
134
|
cat /etc/fstab.bak | grep -v '#{vol_spec['mount']}' > /etc/fstab
|
|
135
|
-
if [[ #{rubber_env.cloud_provider == 'aws'} && `lsb_release -r -s | sed 's/[.].*//'` -gt "10" ]]; then
|
|
135
|
+
if [[ #{rubber_env.cloud_provider == 'aws'} == true ]] && [[ `lsb_release -r -s | sed 's/[.].*//'` -gt "10" ]]; then
|
|
136
136
|
device=`echo #{vol_spec['device']} | sed 's/sd/xvd/'`
|
|
137
137
|
else
|
|
138
138
|
device='#{vol_spec['device']}'
|
data/lib/rubber/version.rb
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
namespace :rubber do
|
|
2
|
+
|
|
3
|
+
namespace :delayed_job do
|
|
4
|
+
|
|
5
|
+
rubber.allow_optional_tasks(self)
|
|
6
|
+
|
|
7
|
+
after "deploy:stop", "rubber:delayed_job:stop"
|
|
8
|
+
after "deploy:start", "rubber:delayed_job:start"
|
|
9
|
+
after "deploy:restart", "rubber:delayed_job:restart"
|
|
10
|
+
|
|
11
|
+
def args
|
|
12
|
+
rubber_env.delayed_job_args || "-n #{rubber_env.num_delayed_job_workers}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc "Stop the delayed_job process"
|
|
16
|
+
task :stop, :roles => :delayed_job do
|
|
17
|
+
rsudo "cd #{current_path} && RAILS_ENV=#{Rubber.env} script/delayed_job stop #{self.args}", :as => rubber_env.app_user
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
desc "Start the delayed_job process"
|
|
21
|
+
task :start, :roles => :delayed_job do
|
|
22
|
+
rsudo "cd #{current_path} && RAILS_ENV=#{Rubber.env} script/delayed_job start #{self.args}", :as => rubber_env.app_user
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc "Restart the delayed_job process"
|
|
26
|
+
task :restart, :roles => :delayed_job do
|
|
27
|
+
rsudo "cd #{current_path} && RAILS_ENV=#{Rubber.env} script/delayed_job restart #{self.args}", :as => rubber_env.app_user
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
desc "Live tail of delayed_job log files for all machines"
|
|
31
|
+
task :tail_logs, :roles => :delayed_job do
|
|
32
|
+
last_host = ""
|
|
33
|
+
log_file_glob = rubber.get_env("FILE", "Log files to tail", true, "#{current_path}/log/delayed_job.log")
|
|
34
|
+
trap("INT") { puts 'Exiting...'; exit 0; } # handle ctrl-c gracefully
|
|
35
|
+
run "tail -qf #{log_file_glob}" do |channel, stream, data|
|
|
36
|
+
puts if channel[:host] != last_host # blank line between different hosts
|
|
37
|
+
host = "[#{channel.properties[:host].gsub(/\..*/, '')}]" # get left-most subdomain
|
|
38
|
+
data.lines { |line| puts "%-15s %s" % [host, line] } # add host name to the start of each line
|
|
39
|
+
last_host = channel[:host]
|
|
40
|
+
break if stream == :err
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<%
|
|
2
|
+
@path = '/etc/monit/monit.d/monit-delayed_job.conf'
|
|
3
|
+
%>
|
|
4
|
+
|
|
5
|
+
<% if rubber_env.num_delayed_job_workers == 1 %>
|
|
6
|
+
check process delayed_job
|
|
7
|
+
with pidfile <%= Rubber.root %>/tmp/pids/delayed_job.pid
|
|
8
|
+
start program = "/usr/bin/sudo -H -u <%= rubber_env.app_user %> /bin/bash -l -c 'RAILS_ENV=<%= Rubber.env %> <%= Rubber.root %>/script/delayed_job start'"
|
|
9
|
+
stop program = "/usr/bin/sudo -H -u <%= rubber_env.app_user %> /bin/bash -l -c 'RAILS_ENV=<%= Rubber.env %> <%= Rubber.root %>/script/delayed_job stop'"
|
|
10
|
+
<% else %>
|
|
11
|
+
<% rubber_env.num_delayed_job_workers.times do |id| %>
|
|
12
|
+
check process delayed_job_<%= id %>
|
|
13
|
+
with pidfile <%= Rubber.root %>/tmp/pids/delayed_job.<%= id %>.pid
|
|
14
|
+
start program = "/usr/bin/sudo -H -u <%= rubber_env.app_user %> /bin/bash -l -c 'RAILS_ENV=<%= Rubber.env %> <%= Rubber.root %>/script/delayed_job start -i <%= id %>'"
|
|
15
|
+
stop program = "/usr/bin/sudo -H -u <%= rubber_env.app_user %> /bin/bash -l -c 'RAILS_ENV=<%= Rubber.env %> <%= Rubber.root %>/script/delayed_job stop -i <%= id %>'"
|
|
16
|
+
group delayed_job
|
|
17
|
+
<% end %>
|
|
18
|
+
<% end %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
num_delayed_job_workers: 1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
description: The Delayed::Job module
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
namespace :rubber do
|
|
2
|
+
|
|
3
|
+
namespace :discourse do
|
|
4
|
+
|
|
5
|
+
after "rubber:postgresql:bootstrap", "rubber:discourse:create_postgres_extensions"
|
|
6
|
+
|
|
7
|
+
task :create_postgres_extensions, :roles => :postgresql_master do
|
|
8
|
+
rsudo "export DEBIAN_FRONTEND=noninteractive; apt-get -q -o Dpkg::Options::=--force-confold -y --force-yes install postgresql-contrib"
|
|
9
|
+
rubber.sudo_script "create_extensions", <<-ENDSCRIPT
|
|
10
|
+
sudo -i -u postgres psql -c "CREATE EXTENSION IF NOT EXISTS hstore;" -d "#{rubber_env.db_name}"
|
|
11
|
+
sudo -i -u postgres psql -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;" -d "#{rubber_env.db_name}"
|
|
12
|
+
ENDSCRIPT
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<%
|
|
2
|
+
@path = "/etc/nginx/nginx.conf"
|
|
3
|
+
@post = "mkdir -p #{rubber_env.nginx_log_dir}"
|
|
4
|
+
%>
|
|
5
|
+
|
|
6
|
+
user www-data;
|
|
7
|
+
worker_processes 10;
|
|
8
|
+
|
|
9
|
+
pid /var/run/nginx.pid;
|
|
10
|
+
|
|
11
|
+
events
|
|
12
|
+
{
|
|
13
|
+
worker_connections 1024;
|
|
14
|
+
}
|
|
15
|
+
|
|
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_min_length 1000;
|
|
30
|
+
gzip_types application/json text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
|
|
31
|
+
|
|
32
|
+
# configure log format like to Apache's "combined" log format
|
|
33
|
+
log_format main
|
|
34
|
+
'$remote_addr - $remote_user [$time_local] '
|
|
35
|
+
'"$request" $status $body_bytes_sent "$http_referer" '
|
|
36
|
+
'"$http_user_agent" "$http_cookie"';
|
|
37
|
+
|
|
38
|
+
# default log files
|
|
39
|
+
error_log <%= rubber_env.nginx_log_dir %>/error.log notice;
|
|
40
|
+
access_log <%= rubber_env.nginx_log_dir %>/access.log main;
|
|
41
|
+
|
|
42
|
+
include /etc/nginx/rubber/*.conf;
|
|
43
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<%
|
|
2
|
+
@path = "/etc/nginx/rubber/unicorn_nginx.conf"
|
|
3
|
+
%>
|
|
4
|
+
|
|
5
|
+
upstream unicorn_server {
|
|
6
|
+
# This is the socket we configured in unicorn.rb
|
|
7
|
+
server unix:/var/run/unicorn.sock
|
|
8
|
+
fail_timeout=0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
server {
|
|
12
|
+
listen 80;
|
|
13
|
+
client_max_body_size 4G;
|
|
14
|
+
server_name <%= [ rubber_env.domain, rubber_env.web_aliases ].flatten.compact.join(" ") %>;
|
|
15
|
+
|
|
16
|
+
sendfile on;
|
|
17
|
+
keepalive_timeout 65;
|
|
18
|
+
|
|
19
|
+
# Location of our static files
|
|
20
|
+
root <%= Rubber.root + "/public" %>;
|
|
21
|
+
set $public <%= Rubber.root + "/public" %>;
|
|
22
|
+
|
|
23
|
+
location / {
|
|
24
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
25
|
+
proxy_set_header Host $http_host;
|
|
26
|
+
proxy_redirect off;
|
|
27
|
+
|
|
28
|
+
# If you don't find the filename in the static files
|
|
29
|
+
# Then request it from the unicorn server
|
|
30
|
+
if (!-f $request_filename) {
|
|
31
|
+
proxy_pass http://unicorn_server;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
location ~ ^/assets/ {
|
|
36
|
+
expires 1y;
|
|
37
|
+
add_header Cache-Control public;
|
|
38
|
+
add_header ETag "";
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
location ~ ^/uploads/ {
|
|
43
|
+
expires 1y;
|
|
44
|
+
add_header Cache-Control public;
|
|
45
|
+
add_header ETag "";
|
|
46
|
+
|
|
47
|
+
## optional upload anti-hotlinking rules
|
|
48
|
+
#valid_referers none blocked mysite.com *.mysite.com;
|
|
49
|
+
#if ($invalid_referer) {
|
|
50
|
+
# return 403;
|
|
51
|
+
#}
|
|
52
|
+
|
|
53
|
+
# let NGINX serve images
|
|
54
|
+
location ~* \.(gif|png|jpg|jpeg|bmp|tif|tiff)$ { try_files $uri =404; }
|
|
55
|
+
location ~ /_optimized/ { try_files $uri =404; }
|
|
56
|
+
|
|
57
|
+
# attachments must go through the rails application to get the right content-disposition header
|
|
58
|
+
proxy_set_header X-Sendfile-Type X-Accel-Redirect;
|
|
59
|
+
proxy_set_header X-Accel-Mapping $public/=/downloads/;
|
|
60
|
+
proxy_pass http://unicorn_server;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
try_files $uri @discourse;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
location /downloads/ {
|
|
68
|
+
internal;
|
|
69
|
+
alias $public/;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
location @discourse {
|
|
73
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
74
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
75
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
76
|
+
proxy_set_header Host $http_host;
|
|
77
|
+
|
|
78
|
+
proxy_pass http://unicorn_server;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# this rewrites all the requests to the maintenance.html
|
|
82
|
+
# page if it exists in the doc root. This is for capistrano's
|
|
83
|
+
# disable web task
|
|
84
|
+
if (-f $document_root/system/maintenance.html)
|
|
85
|
+
{
|
|
86
|
+
rewrite ^(.*)$ /system/maintenance.html last;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
error_page 500 502 503 504 /500.html;
|
|
91
|
+
location = /500.html
|
|
92
|
+
{
|
|
93
|
+
root <%= Rubber.root + "/public" %>;
|
|
94
|
+
}
|
|
95
|
+
error_page 404 /404.html;
|
|
96
|
+
location = /404.html
|
|
97
|
+
{
|
|
98
|
+
root <%= Rubber.root + "/public" %>;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<%
|
|
2
|
+
@path = "#{Rubber.root}/config/unicorn.rb"
|
|
3
|
+
current_path = "/mnt/#{rubber_env.app_name}-#{Rubber.env}/current"
|
|
4
|
+
%>
|
|
5
|
+
|
|
6
|
+
worker_processes 2
|
|
7
|
+
working_directory "<%= Rubber.root %>"
|
|
8
|
+
|
|
9
|
+
# This loads the application in the master process before forking
|
|
10
|
+
# worker processes
|
|
11
|
+
# Read more about it here:
|
|
12
|
+
# http://unicorn.bogomips.org/Unicorn/Configurator.html
|
|
13
|
+
preload_app true
|
|
14
|
+
|
|
15
|
+
timeout 30
|
|
16
|
+
|
|
17
|
+
# This is where we specify the socket.
|
|
18
|
+
# We will point the upstream Nginx module to this socket later on
|
|
19
|
+
listen "/var/run/unicorn.sock", :backlog => 64
|
|
20
|
+
|
|
21
|
+
pid "/var/run/unicorn.pid"
|
|
22
|
+
|
|
23
|
+
# Set the path of the log files inside the log folder of the testapp
|
|
24
|
+
stderr_path "<%= Rubber.root %>/log/unicorn.stderr.log"
|
|
25
|
+
stdout_path "<%= Rubber.root %>/log/unicorn.stdout.log"
|
|
26
|
+
|
|
27
|
+
# Because of Capistano, we need to tell unicorn where find the current Gemfile
|
|
28
|
+
# Read about Unicorn, Capistrano, and Bundler here:
|
|
29
|
+
# http://unicorn.bogomips.org/Sandbox.html
|
|
30
|
+
before_exec do |server|
|
|
31
|
+
ENV['BUNDLE_GEMFILE'] = "<%= current_path %>/Gemfile"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
initialized = false
|
|
35
|
+
before_fork do |server, worker|
|
|
36
|
+
unless initialized
|
|
37
|
+
# load up the yaml for the localization bits, in master process
|
|
38
|
+
I18n.t(:posts)
|
|
39
|
+
# get rid of rubbish so we don't share it
|
|
40
|
+
GC.start
|
|
41
|
+
end
|
|
42
|
+
ActiveRecord::Base.connection.disconnect!
|
|
43
|
+
$redis.client.disconnect
|
|
44
|
+
##
|
|
45
|
+
# When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
|
|
46
|
+
# immediately start loading up a new version of itself (loaded with a new
|
|
47
|
+
# version of our app). When this new Unicorn is completely loaded
|
|
48
|
+
# it will begin spawning workers. The first worker spawned will check to
|
|
49
|
+
# see if an .oldbin pidfile exists. If so, this means we've just booted up
|
|
50
|
+
# a new Unicorn and need to tell the old one that it can now die. To do so
|
|
51
|
+
# we send it a QUIT.
|
|
52
|
+
#
|
|
53
|
+
# Using this method we get 0 downtime deploys.
|
|
54
|
+
old_pid = "/var/run/unicorn.pid.oldbin"
|
|
55
|
+
if File.exists?(old_pid) && server.pid != old_pid
|
|
56
|
+
begin
|
|
57
|
+
Process.kill("QUIT", File.read(old_pid).to_i)
|
|
58
|
+
rescue Errno::ENOENT, Errno::ESRCH
|
|
59
|
+
# someone else did our job for us
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# This option works in together with preload_app true setting
|
|
64
|
+
# What is does is prevent the master process from holding
|
|
65
|
+
# the database connection
|
|
66
|
+
defined?(ActiveRecord::Base) and
|
|
67
|
+
ActiveRecord::Base.connection.disconnect!
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
after_fork do |server, worker|
|
|
72
|
+
# Unicorn master is started as root, which is fine, but let's
|
|
73
|
+
# drop the workers to www-data:www-data
|
|
74
|
+
begin
|
|
75
|
+
uid, gid = Process.euid, Process.egid
|
|
76
|
+
user, group = '<%=rubber_env.app_user %>', '<%=rubber_env.app_user %>'
|
|
77
|
+
target_uid = Etc.getpwnam(user).uid
|
|
78
|
+
target_gid = Etc.getgrnam(group).gid
|
|
79
|
+
worker.tmp.chown(target_uid, target_gid)
|
|
80
|
+
if uid != target_uid || gid != target_gid
|
|
81
|
+
Process.initgroups(user, target_gid)
|
|
82
|
+
Process::GID.change_privilege(target_gid)
|
|
83
|
+
Process::UID.change_privilege(target_uid)
|
|
84
|
+
end
|
|
85
|
+
rescue => e
|
|
86
|
+
if RAILS_ENV == 'development'
|
|
87
|
+
STDERR.puts "couldn't change user, oh well"
|
|
88
|
+
else
|
|
89
|
+
raise e
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Here we are establishing the connection after forking worker
|
|
94
|
+
# processes
|
|
95
|
+
ActiveRecord::Base.establish_connection
|
|
96
|
+
$redis.client.reconnect
|
|
97
|
+
Rails.cache.reconnect
|
|
98
|
+
MessageBus.after_fork
|
|
99
|
+
end
|