From bcdc10220b2aaa598cd36d6ba621490a7cf541ba Mon Sep 17 00:00:00 2001 From: Ilya Krasilnikov Date: Wed, 26 Oct 2011 02:30:39 +0400 Subject: [PATCH] unicorn --- config/deploy.rb | 48 +++++++++++++++++------------------------------ config/unicorn.rb | 28 +++------------------------ script/unicorn | 4 ++-- 3 files changed, 22 insertions(+), 58 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index fbaf4ad94..52a692be8 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,36 +1,35 @@ -# RVM bootstrap -$:.unshift(File.expand_path("~/.rvm/lib")) +$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) require 'rvm/capistrano' -set :rvm_ruby_string, 'ree@rails-3.0.5' +require 'bundler/capistrano' +require 'airbrake/capistrano' + set :rvm_type, :user # bundler bootstrap -require 'bundler/capistrano' # main details ssh_options[:forward_agent] = true -set :application, "rosa_build" -set :user, "rosa_build" -default_run_options[:pty] = true +set :application, "rosa_build" + +set :repository, "git@github.com:warpc/rosa-build.git" +set :branch, "master" +# set :git_shallow_clone, 1 set :scm, "git" -set :deploy_to, "/var/www/#{application}" - -set :domain, "abs.rosalab.ru" -set :port, 222 +set :user, "rosa" +set :domain, "195.19.76.12" # "abs.rosalab.ru" +set :port, 1822 # 222 +set :use_sudo, false +set :deploy_to, "/srv/#{application}" role :app, domain role :web, domain role :db, domain, :primary => true -ssh_options[:auth_methods] = %w(publickey password) -set :use_sudo, false -set :repository, "git@github.com:warpc/rosa-build.git" -set :branch, "master" -set :git_shallow_clone, 1 set :keep_releases, 3 + task :symlink_config_files do run "mkdir -p #{deploy_to}/#{shared_dir}/config" @@ -38,12 +37,11 @@ task :symlink_config_files do run "yes y | cp -i #{release_path}/config/application.yml.sample #{deploy_to}/#{shared_dir}/config/application.yml" - run "ln -nfs #{deploy_to}/#{shared_dir}/config/database.yml #{release_path}/config/database.yml" - run "ln -nfs #{deploy_to}/#{shared_dir}/config/application.yml #{release_path}/config/application.yml" + run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" + run "ln -nfs #{shared_path}/config/application.yml #{release_path}/config/application.yml" end namespace :deploy do - desc "Restarting mod_rails with restart.txt" task :restart, :roles => :app, :except => { :no_release => true } do ## DISABLED: run "cd #{deploy_to}/current ; ([ -f tmp/pids/unicorn.pid ] && kill -USR2 `cat tmp/pids/unicorn.pid`); true" run ["#{current_path}/script/unicorn reload"].join("; ") @@ -57,11 +55,6 @@ namespace :deploy do run "cd #{deploy_to}/current ; RAILS_ENV=production ./script/delayed_job stop; RAILS_ENV=production ./script/delayed_job start; true" end - desc "Rude restart application" - task :rude_restart, :roles => :web do - run "cd #{deploy_to}/current ; pkill unicorn; sleep 0.5; pkill -9 unicorn; sleep 0.5 ; unicorn_rails -c config/unicorn.rb -E production -D " - end - # desc 'Bundle and minify the JS and CSS files' # task :build_assets, :roles => :app do # root_path = File.expand_path(File.dirname(__FILE__) + '/..') @@ -79,11 +72,4 @@ namespace :deploy do # build_assets symlink_config_files end - - after "deploy:migrate", :roles => :web do - restart - end end - -# require './config/boot' -require 'airbrake/capistrano' diff --git a/config/unicorn.rb b/config/unicorn.rb index 019780134..75ca6a78e 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -12,7 +12,7 @@ listen '/tmp/rosa_build.sock', :backlog => 2048 timeout 120 # #feel free to point this anywhere accessible on the filesystem -pid "/var/www/rosa_build/current/tmp/pids/unicorn.pid" +pid "/srv/rosa/rosa_build/current/tmp/pids/unicorn.pid" # # REE @@ -24,35 +24,13 @@ end # By default, the Unicorn logger will write to stderr. # Additionally, ome applications/frameworks log to stderr or stdout, # so prevent them from going to /dev/null when daemonized here: -stderr_path "/var/www/rosa_build/shared/log/unicorn.stderr.log" -stdout_path "/var/www/rosa_build/shared/log/unicorn.stdout.log" +stderr_path "/srv/rosa/rosa_build/shared/log/unicorn.stderr.log" +stdout_path "/srv/rosa/rosa_build/shared/log/unicorn.stdout.log" # combine REE with "preload_app true" for memory savings # http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow preload_app true -before_fork do |server, worker| - ## - # 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. - - old_pid = '/var/www/rosa_build/current/tmp/pids/unicorn.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 - before_fork do |server, worker| ## # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and diff --git a/script/unicorn b/script/unicorn index 6e31ea719..1fd451ad0 100755 --- a/script/unicorn +++ b/script/unicorn @@ -1,10 +1,10 @@ #!/bin/sh -current_path="/var/www/rosa_build/current" +current_path="/srv/rosa/rosa_build/current" getpid() { - pid=`ps ax |grep "unicorn_rails master -c /var/www/rosa_build" \ + pid=`ps ax |grep "unicorn_rails master -c /srv/rosa/rosa_build" \ |grep -v grep \ |awk '{print $1}'`; }