forked from Antiarchitect/taurus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,7 @@ gem "erubis" | |
gem "haml" | ||
gem "pdfkit" | ||
gem "pg" | ||
|
||
group :production do | ||
gem 'unicorn' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
deploy_to = "/srv/taurus" | ||
rails_root = "#{deploy_to}/current" | ||
pid_file = "#{deploy_to}/shared/pids/unicorn.pid" | ||
socket_file= "#{deploy_to}/shared/pids/unicorn.sock" | ||
log_file = "#{rails_root}/log/unicorn.log" | ||
err_log = "#{rails_root}/log/unicorn_error.log" | ||
old_pid = pid_file + '.oldbin' | ||
|
||
timeout 60 | ||
worker_processes 4 | ||
listen socket_file, :backlog => 2048 | ||
pid pid_file | ||
stderr_path err_log | ||
stdout_path log_file | ||
|
||
preload_app true | ||
|
||
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=) | ||
|
||
before_exec do |server| | ||
ENV["BUNDLE_GEMFILE"] = "#{rails_root}/Gemfile" | ||
end | ||
|
||
before_fork do |server, worker| | ||
# the following is highly recomended for Rails + "preload_app true" | ||
# as there's no need for the master process to hold a connection | ||
defined?(ActiveRecord::Base) and | ||
ActiveRecord::Base.connection.disconnect! | ||
|
||
## | ||
# When sent a USR2, Unicorn will suffix its pidfile with .oldbin and | ||
# immediately start loading up a new version of itself (loaded with a new | ||
# version of our app). When this new Unicorn is completely loaded | ||
# it will begin spawning workers. The first worker spawned will check to | ||
# see if an .oldbin pidfile exists. If so, this means we've just booted up | ||
# a new Unicorn and need to tell the old one that it can now die. To do so | ||
# we send it a QUIT. | ||
# | ||
# Using this method we get 0 downtime deploys. | ||
|
||
if File.exists?(old_pid) && server.pid != old_pid | ||
begin | ||
Process.kill("QUIT", File.read(old_pid).to_i) | ||
rescue Errno::ENOENT, Errno::ESRCH | ||
# someone else did our job for us | ||
end | ||
end | ||
end | ||
|
||
after_fork do |server, worker| | ||
defined?(ActiveRecord::Base) and | ||
ActiveRecord::Base.establish_connection | ||
end |