add unicorn support
This commit is contained in:
@@ -19,6 +19,8 @@ set :scm, :git
|
||||
set :user, "albert"
|
||||
set :deploy_to, "/var/www/danbooru2"
|
||||
|
||||
require 'capistrano-unicorn'
|
||||
|
||||
default_run_options[:pty] = true
|
||||
|
||||
namespace :local_config do
|
||||
@@ -101,11 +103,6 @@ namespace :deploy do
|
||||
task :precompile_assets do
|
||||
run "cd #{current_path}; bundle exec rake assets:precompile"
|
||||
end
|
||||
|
||||
desc "Restart the application"
|
||||
task :restart do
|
||||
run "touch #{current_path}/tmp/restart.txt"
|
||||
end
|
||||
end
|
||||
|
||||
namespace :delayed_job do
|
||||
@@ -145,7 +142,8 @@ after "deploy:stop", "delayed_job:stop"
|
||||
after "deploy:restart", "delayed_job:restart"
|
||||
before "deploy:update", "deploy:web:disable"
|
||||
after "deploy:update", "deploy:migrate"
|
||||
after "deploy:update", "deploy:restart"
|
||||
after "deploy:restart", "unicorn:reload"
|
||||
after "deploy:restart", "unicorn:restart"
|
||||
after "deploy:restart", "deploy:precompile_assets"
|
||||
after "deploy:restart", "deploy:web:enable"
|
||||
after "delayed_job:stop", "delayed_job:kill"
|
||||
|
||||
46
config/unicorn.rb
Normal file
46
config/unicorn.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
# Set your full path to application.
|
||||
app_path = "/var/www/danbooru2/current"
|
||||
|
||||
# Set unicorn options
|
||||
if Socket.gethostname =~ /sonohara|hijiribe/
|
||||
worker_processes 12
|
||||
else
|
||||
worker_processes 1
|
||||
end
|
||||
|
||||
preload_app false
|
||||
timeout 180
|
||||
listen "127.0.0.1:9000"
|
||||
|
||||
# Spawn unicorn master worker for user apps (group: apps)
|
||||
user 'albert', 'albert'
|
||||
|
||||
# Fill path to your app
|
||||
working_directory app_path
|
||||
|
||||
# Should be 'production' by default, otherwise use other env
|
||||
rails_env = ENV['RAILS_ENV'] || 'production'
|
||||
|
||||
# Log everything to one file
|
||||
stderr_path "log/unicorn.log"
|
||||
stdout_path "log/unicorn.log"
|
||||
|
||||
# Set master PID location
|
||||
pid "#{app_path}/tmp/pids/unicorn.pid"
|
||||
|
||||
before_fork do |server, worker|
|
||||
ActiveRecord::Base.connection.disconnect!
|
||||
|
||||
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
|
||||
# someone else did our job for us
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
after_fork do |server, worker|
|
||||
ActiveRecord::Base.establish_connection
|
||||
end
|
||||
Reference in New Issue
Block a user