Skip to content

Commit

Permalink
Added some nice debug recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
mraaroncruz committed Sep 10, 2012
1 parent b22599f commit a41c097
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 4 deletions.
9 changes: 9 additions & 0 deletions bundler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace :bundler do
task :install do
run <<-RUN
cd #{release_path} && \
bundle install --path #{shared_path}/bundle --without development test
RUN
end
before 'deploy:finalize_update', 'bundler:install'
end
7 changes: 7 additions & 0 deletions carrierwave.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace :carrierwave do
task :symlink, roles: :app do
run "ln -nfs #{shared_path}/uploads/ #{release_path}/public/uploads"
end
after "deploy:finalize_update", "carrierwave:symlink"
end

6 changes: 6 additions & 0 deletions logs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace :logs do
desc "Get ouput of env's log file"
task :tail do
stream "tail -n 300 -f #{current_path}/log/#{stage}.log"
end
end
2 changes: 1 addition & 1 deletion nginx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
restart
end
after "deploy:setup", "nginx:setup"

%w[start stop restart].each do |command|
desc "#{command} nginx"
task command, roles: :web do
Expand Down
4 changes: 2 additions & 2 deletions passenger.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace :passenger do
task :start {}
task :stop {}
task :start do end
task :stop do end
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
Expand Down
8 changes: 8 additions & 0 deletions postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "postgresql:symlink"

desc "database console"
task :console do
auth = capture "cat #{shared_path}/config/database.yml"
puts "PASSWORD::: #{auth.match(/password: (.*$)/).captures.first}"
hostname = find_servers_for_task(current_task).first
exec "ssh #{hostname} -t 'source ~/.zshrc && psql -U #{application} #{postgresql_database}'"
end
end
7 changes: 7 additions & 0 deletions pry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace :pry do
desc "Connect to console"
task :console do
hostname = find_servers_for_task(current_task).first
exec "ssh #{hostname} -t 'source ~/.zshrc && cd #{current_path} && bundle exec bin/prys'"
end
end
44 changes: 44 additions & 0 deletions resque.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'resque'

set_default(:resque_worker_count, 4)

# Start a worker with proper env vars and output redirection
def run_worker(queue = "*", count = 1)
puts "Starting #{count} worker(s) with QUEUE: #{queue}"
ops = {:pgroup => true,
:err => [
(File.expand_path('../../../', __FILE__) + "/log/resque_err").to_s, "a"],
:out => [
(File.expand_path('../../../', __FILE__) + "/log/resque_stdout").to_s, "a"]
}
env_vars = {"QUEUE" => queue.to_s}
count.times {
## Using Kernel.spawn and Process.detach because regular system() call would
## cause the processes to quit when capistrano finishes
pid = spawn(env_vars, "bundle exec rake resque:work", ops)
Process.detach(pid)
}
end

namespace :resque do

desc "Start resque processes"
task :start do
run ". ~/.zshrc && cd #{current_path} && bundle exec rake resque:start"
end

desc "Quit running workers"
task :stop do
run ". /home/#{user}/.zshrc && cd #{current_path} && bundle exec rake resque:stop"
end

desc "Restart running workers"
task :restart do
stop
start
end

%w[stop start restart].each do |command|
after "deploy:#{command}", "resque:#{command}"
end
end
15 changes: 14 additions & 1 deletion unicorn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,24 @@
end
after "deploy:setup", "unicorn:setup"

%w[start stop restart].each do |command|
%w[start stop].each do |command|
desc "#{command} unicorn"
task command, roles: :app do
run "service unicorn_#{application} #{command}"
end
after "deploy:#{command}", "unicorn:#{command}"
end

desc "Restart unicorn"
task :restart, roles: :app do
stop
sleep 4
start
end
after "deploy:restart", "unicorn:restart"

desc "Get ouput of unicorn log file"
task :tail do
stream "tail -n 300 -f #{unicorn_log}"
end
end

0 comments on commit a41c097

Please sign in to comment.