From 2bee3bd25d1a6b02f53700fb25022e0e7fec8cff Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Mon, 5 Dec 2011 21:34:26 +0200 Subject: [PATCH] Code cleanup. Redo deploy to unicorn. Refs #2261 --- Gemfile.lock | 8 -------- app/models/product.rb | 16 ---------------- config/deploy.rb | 24 ++++++++++++++++++++++-- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ee0589a47..43c3068c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -55,7 +55,6 @@ GEM chronic (0.6.6) cocaine (0.2.0) columnize (0.3.5) - daemon_controller (0.2.6) daemons (1.1.4) delayed_job (2.1.4) activesupport (~> 3.0) @@ -72,7 +71,6 @@ GEM factory_girl_rails (1.4.0) factory_girl (~> 2.3.0) railties (>= 3.0.0) - fastthread (1.0.7) grit (2.4.1) diff-lcs (~> 1.1) mime-types (~> 1.15) @@ -121,11 +119,6 @@ GEM activesupport (>= 2.3.2) cocaine (>= 0.0.2) mime-types - passenger (3.0.11) - daemon_controller (>= 0.2.5) - fastthread (>= 1.0.1) - rack - rake (>= 0.8.1) pg (0.11.0) polyglot (0.3.3) rack (1.2.4) @@ -228,7 +221,6 @@ DEPENDENCIES omniauth (~> 1.0.1) omniauth-openid (~> 1.0.1) paperclip (~> 2.3) - passenger (~> 3.0.11) pg (~> 0.11.0) rails (= 3.0.11) rails-xmlrpc (~> 0.3.6) diff --git a/app/models/product.rb b/app/models/product.rb index aa9abc8ca..637fdee90 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -16,22 +16,6 @@ class Product < ActiveRecord::Base scope :recent, order("name ASC") - # attr_accessor :tmp_upload_dir - # after_save lambda { FileUtils.rm_rf(tmp_upload_dir) if tmp_upload_dir and File.directory?(tmp_upload_dir) } - # - # def tar_with_fast=(file) - # if file.present? and file.respond_to?('[]') - # self.tmp_upload_dir = "#{file['filepath']}_1" - # tmp_file_path = File.join tmp_upload_dir, file['original_name'] - # FileUtils.mkdir_p tmp_upload_dir - # FileUtils.mv file['filepath'], tmp_file_path - # self.tar_without_fast = File.open tmp_file_path, 'rb' - # else - # self.tar_without_fast = file - # end - # end - # alias_method_chain :tar=, :fast - def delete_tar @delete_tar ||= "0" end diff --git a/config/deploy.rb b/config/deploy.rb index e39b83ca9..b47b4fe5c 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -24,6 +24,7 @@ set :repository, "git@github.com:warpc/rosa-build.git" set :scm, "git" set :user, "rosa" +# set :sudo, "rvmsudo" set :use_sudo, false set :deploy_to, "/srv/#{application}" # set :deploy_via, :copy @@ -31,6 +32,11 @@ set :deploy_to, "/srv/#{application}" set :keep_releases, 3 +set :rails_env, :production +set :unicorn_binary, "bundle exec unicorn" +set :unicorn_config, "#{current_path}/config/unicorn.rb" +set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid" + task :symlink_config_files do run "mkdir -p #{deploy_to}/#{shared_dir}/config" @@ -53,12 +59,26 @@ task :symlink_tmp_dir do end namespace :deploy do + task :start, :roles => :app, :except => { :no_release => true } do + run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D" + end + task :stop, :roles => :app, :except => { :no_release => true } do + run "#{try_sudo} kill `cat #{unicorn_pid}`" + end + task :graceful_stop, :roles => :app, :except => { :no_release => true } do + run "#{try_sudo} kill -s QUIT `cat #{unicorn_pid}`" + end + task :reload, :roles => :app, :except => { :no_release => true } do + run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`" + end task :restart, :roles => :app, :except => { :no_release => true } do - run "touch #{current_release}/tmp/restart.txt" + stop + start + # run "touch #{current_release}/tmp/restart.txt" restart_dj end - %w(start).each { |name| task name, :roles => :app do deploy.restart end } + # %w(start).each { |name| task name, :roles => :app do deploy.restart end } desc "Restart delayed job" task :restart_dj, :roles => :web do