diff options
| -rw-r--r-- | Procfile | 2 | ||||
| -rw-r--r-- | Vagrantfile | 2 | ||||
| -rw-r--r-- | config/unicorn.rb | 26 |
3 files changed, 28 insertions, 2 deletions
@@ -1 +1 @@ -web: rails s -b 0.0.0.0 +web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb diff --git a/Vagrantfile b/Vagrantfile index dd4a8c2..a4f760a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -8,7 +8,7 @@ Vagrant.configure("2") do |config| # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. #config.vm.network :forwarded_port, guest: 80, host: 8080 - config.vm.network :forwarded_port, guest: 3000, host: 3000 + config.vm.network :forwarded_port, guest: 5000, host: 3000 config.vm.provision :shell, :path => 'bin/bootstrap.sh' config.ssh.forward_agent = true diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 0000000..06529c3 --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,26 @@ +worker_processes 8 +timeout 15 +preload_app true + +before_fork do |server, worker| + Signal.trap 'TERM' do + puts 'Unicorn master intercepting TERM and sending myself QUIT instead' + Process.kill 'QUIT', Process.pid + end + + if defined?(ActiveRecord::Base) + ActiveRecord::Base.connection.disconnect! + Rails.logger.info('Disconnected from ActiveRecord') + end +end + +after_fork do |server, worker| + Signal.trap 'TERM' do + puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT' + end + + if defined?(ActiveRecord::Base) + ActiveRecord::Base.establish_connection + Rails.logger.info('Connected to ActiveRecord') + end +end |
