Commit 604f2de5a739adfdde370421efaeac6e408f8a7d
1 parent
70def36d
Exists in
production
adjusts for script unicorn
Showing
5 changed files
with
85 additions
and
4 deletions
Show diff stats
.gitignore
config/unicorn.default.rb
1 | 1 | # http://michaelvanrooijen.com/articles/2011/06/01-more-concurrency-on-a-single-heroku-dyno-with-the-new-celadon-cedar-stack/ |
2 | 2 | |
3 | -worker_processes 3 # amount of unicorn workers to spin up | |
3 | +worker_processes ENV['ERRBIT_UNICORN_WORKER_PROCESSES'] # amount of unicorn workers to spin up | |
4 | 4 | timeout 30 # restarts workers that hang for 30 seconds |
5 | 5 | preload_app true |
6 | -listen ENV['PORT'] || 8080 | |
7 | -pid ENV['UNICORN_PID'] if ENV['UNICORN_PID'] | |
6 | + | |
7 | +listen "${ENV['ERRBIT_UNICORN_BIND_ADDRESS'}:${ENV['ERRBIT_UNICORN_PORT']}" | |
8 | + | |
9 | +pid ENV['ERRBIT_UNICORN_PID'] | |
8 | 10 | |
9 | 11 | # Taken from github: https://github.com/blog/517-unicorn |
10 | 12 | # Though everyone uses pretty miuch the same code |
... | ... | @@ -19,6 +21,8 @@ before_fork do |server, _worker| |
19 | 21 | # we send it a QUIT. |
20 | 22 | # |
21 | 23 | # Using this method we get 0 downtime deploys. |
24 | + ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base) | |
25 | + | |
22 | 26 | |
23 | 27 | old_pid = "#{server.config[:pid]}.oldbin" |
24 | 28 | if File.exist?(old_pid) && server.pid != old_pid |
... | ... | @@ -29,3 +33,9 @@ before_fork do |server, _worker| |
29 | 33 | end |
30 | 34 | end |
31 | 35 | end |
36 | + | |
37 | + | |
38 | +after_fork do |server, worker| | |
39 | + ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base) | |
40 | +end | |
41 | + | ... | ... |
... | ... | @@ -0,0 +1,41 @@ |
1 | +# http://michaelvanrooijen.com/articles/2011/06/01-more-concurrency-on-a-single-heroku-dyno-with-the-new-celadon-cedar-stack/ | |
2 | + | |
3 | +worker_processes ENV['ERRBIT_UNICORN_WORKER_PROCESSES'] # amount of unicorn workers to spin up | |
4 | +timeout 30 # restarts workers that hang for 30 seconds | |
5 | +preload_app true | |
6 | + | |
7 | +listen "${ENV['ERRBIT_UNICORN_BIND_ADDRESS'}:${ENV['ERRBIT_UNICORN_PORT']}" | |
8 | + | |
9 | +pid ENV['ERRBIT_UNICORN_PID'] | |
10 | + | |
11 | +# Taken from github: https://github.com/blog/517-unicorn | |
12 | +# Though everyone uses pretty miuch the same code | |
13 | +before_fork do |server, _worker| | |
14 | + ## | |
15 | + # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and | |
16 | + # immediately start loading up a new version of itself (loaded with a new | |
17 | + # version of our app). When this new Unicorn is completely loaded | |
18 | + # it will begin spawning workers. The first worker spawned will check to | |
19 | + # see if an .oldbin pidfile exists. If so, this means we've just booted up | |
20 | + # a new Unicorn and need to tell the old one that it can now die. To do so | |
21 | + # we send it a QUIT. | |
22 | + # | |
23 | + # Using this method we get 0 downtime deploys. | |
24 | + ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base) | |
25 | + | |
26 | + | |
27 | + old_pid = "#{server.config[:pid]}.oldbin" | |
28 | + if File.exist?(old_pid) && server.pid != old_pid | |
29 | + begin | |
30 | + Process.kill("QUIT", File.read(old_pid).to_i) | |
31 | + rescue Errno::ENOENT, Errno::ESRCH | |
32 | + warn "Unicorn: master process already killed, no problem" | |
33 | + end | |
34 | + end | |
35 | +end | |
36 | + | |
37 | + | |
38 | +after_fork do |server, worker| | |
39 | + ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base) | |
40 | +end | |
41 | + | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +#!/bin/bash | |
2 | +# SCRIPT DE INICIALIZAÇÃO DO ERRBIT | |
3 | +# DEVE ser chamado este script com as variável de ambiente ERRBIT_CONF_PATH e ERRBIT_APP_PATH sendo definida s | |
4 | +# | |
5 | +# exemplo: | |
6 | +# | |
7 | +# ERRBIT_CONF_PATH=/opt/appconf/errbit/ /opt/websites/errbit/start.sh | |
8 | +# | |
9 | +# Em ERRBIT_CONF_PATH deve ser colocado um unicorn.rb que pode ser criado a partir exemplo em config/unicorn.default.rb | |
10 | +echo "Starting Errbit" | |
11 | + | |
12 | +echo "ERRBIT_CONF_PATH=$ERRBIT_CONF_PATH" | |
13 | + | |
14 | +if [ ! -d $ERRBIT_CONF_PATH ]; then | |
15 | + echo "ERRBIT_CONF_PATH não definido ou diretório $ERRBIT_CONF_PATH não encontrado"; | |
16 | + exit 1; | |
17 | +fi | |
18 | + | |
19 | +# default variable | |
20 | +export ERRBIT_UNICORN_BIND_ADDRESS=127.0.0.1 | |
21 | +export ERRBIT_UNICORN_PID=errbit_unicorn.pid | |
22 | +export ERRBIT_UNICORN_PORT=4040 | |
23 | +export ERRBIT_UNICORN_WORKER_PROCESSES=1 | |
24 | + | |
25 | +# ambiente.sh deve sobrescrever exportando as seguintes variáveis ERRBIT_UNICORN_PID, ERRBIT_UNICORN_PORT, ERRBIT_UNICORN_WORKER_PROCESSES | |
26 | + | |
27 | +if [ -f $ERRBIT_CONF_PATH/ambiente.sh ]; then | |
28 | + source $ERRBIT_CONF_PATH/ambiente.sh | |
29 | +fi | |
30 | + | |
31 | +unicorn -c $ERRBIT_CONF_PATH/conf/unicorn.rb | ... | ... |