Skip to content

Commit

Permalink
restart resque-pool on deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Alicia Cozine committed May 2, 2017
1 parent 578a6ed commit 7183562
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 39 deletions.
56 changes: 17 additions & 39 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,26 @@
# Default branch is :master
set :branch, ENV['REVISION'] || ENV['BRANCH_NAME'] || 'master'

set :linked_dirs, %w[
tmp/pids
tmp/cache
tmp/sockets
public/assets
]
append :linked_dirs, "tmp/pids", "tmp/cache", "tmp/sockets", "public/assets"

set :linked_files, %w[
config/blacklight.yml
config/database.yml
config/fedora.yml
config/redis.yml
config/resque-pool.yml
config/role_map.yml
config/secrets.yml
config/solr.yml
]
append :linked_files, "config/blacklight.yml", "config/database.yml", "config/fedora.yml", "config/redis.yml", "config/resque-pool.yml", "config/role_map.yml", "config/secrets.yml", "config/solr.yml"

# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, "/var/www/my_app_name"

# Default value for :format is :airbrussh.
# set :format, :airbrussh

# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto

# Default value for :pty is false
# set :pty, true
# restart resque-pool
require 'resque'

# Default value for :linked_files is []
# append :linked_files, "config/database.yml", "config/secrets.yml"
set :resque_kill_signal, 'QUIT'

# Default value for linked_dirs is []
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"
namespace :deploy do
before :restart, 'resque:pool:stop'

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end

# Default value for keep_releases is 5
# set :keep_releases, 5
after :clear_cache, 'resque:pool:start'
end
34 changes: 34 additions & 0 deletions lib/capistrano/tasks/resque.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace :resque do
namespace :pool do
desc 'Stop resque pool'
task :stop do
on roles(:resque_pool), in: :sequence, wait: 5 do
# Shuts down resque_pool master if pid exists
if test("[ -f #{shared_path}/tmp/pids/resque-pool.pid ]")
execute "export master_pid=$(cat #{shared_path}/tmp/pids/resque-pool.pid) && kill -QUIT $master_pid"
else
warn 'No resque-pool pid found'
end
end
end

desc 'Start resque pool'
task :start do
on roles(:resque_pool), in: :sequence, wait: 10 do
# Starts a new resque_pool master
execute "cd #{release_path} && bundle exec resque-pool -d -E #{fetch(:rails_env)} -c config/resque-pool.yml -p #{shared_path}/tmp/pids/resque-pool.pid -e #{fetch(:resque_stderr_log)} -o #{fetch(:resque_stdout_log)}"
end
end

desc 'Restart resque pool'
task :restart do
invoke 'resque:pool:stop'
invoke 'resque:pool:start'
end
end

# From https://github.com/sshingler/capistrano-resque/blob/master/lib/capistrano-resque/tasks/capistrano-resque.rake
def output_redirection
">> #{fetch(:resque_stdout_log)} 2>> #{fetch(:resque_stderr_log)}"
end
end

0 comments on commit 7183562

Please sign in to comment.