Skip to content

Instantly share code, notes, and snippets.

@phstc phstc/app
Last active Jun 25, 2016

Embed
What would you like to do?
# /etc/nginx/sites-available/app
upstream app_server {
server unix:/tmp/.unicorn_app.sock fail_timeout=0;
}
server {
listen 80;
server_name app.com;
location / {
proxy_pass http://app_server;
proxy_set_header Host $host;
proxy_redirect off;
}
}
# /etc/monit/conf.d/app.conf
check process app with pidfile /home/ubuntu/app/shared/pids/unicorn.pid
stop program = "/bin/su - ubuntu -c '/home/ubuntu/unicorn-stop.sh'" with timeout 60 seconds
start program = "/bin/su - ubuntu -c '/home/ubuntu/unicorn-start.sh'" with timeout 60 seconds
#!/bin/bash
pkill -USR2 -f unicorn_rails.*master
exit 0
#!/bin/bash
cd /home/ubuntu/app/current
export GEM_HOME=/home/ubuntu/.rvm/gems/ruby-1.9.3-p286@global/
export RAILS_ENV=production
export PATH=/home/ubuntu/.rvm/rubies/ruby-1.9.3-p286/bin/:/home/ubuntu/.rvm/gems/ruby-1.9.3-p286/bin/:$PATH
/home/ubuntu/.rvm/gems/ruby-1.9.3-p286@global/bin/bundle exec unicorn_rails -p 9000 -c /home/ubuntu/app/current/config/unicorn.conf.rb -D
exit 0
#!/bin/bash
pkill -f unicorn_rails.*master
exit 0
# app/current/config/unicorn.conf.rb
# -*- encoding : utf-8 -*-
# Unicorn configuration file
listen "/tmp/.unicorn_app.sock", :backlog => 64
worker_processes 3
pid "/home/ubuntu/app/shared/pids/unicorn.pid"
stderr_path "/home/ubuntu/app/log/vitrine-error.log"
stdout_path "/home/ubuntu/app/log/vitrine.log"
timeout 30
preload_app true
before_fork do |server, worker|
# stops old master
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base)
end
after_fork do |server, worker|
ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base)
::NewRelic::Agent.after_fork(:force_reconnect => true) if defined? Unicorn
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.