From 3b0bf893353c39e8c58952f8ab9b82982a19b66e Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Sat, 4 Feb 2012 12:07:26 +0100 Subject: [PATCH 1/4] capistrano deploy: avoid installing heroku gemset group --- config/deploy.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/deploy.rb b/config/deploy.rb index 8d811d5d9..c7e3e8631 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -20,6 +20,7 @@ set :use_sudo, false set :scm_verbose, true set :repository_cache, "remote_cache" set :deploy_via, :checkout +set :bundle_without, [:development, :test, :heroku] # Figure out the name of the current local branch def current_git_branch From 23212e4146b70f5e9f2e5d83d262d2fd53d3ddc1 Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Sat, 4 Feb 2012 12:12:10 +0100 Subject: [PATCH 2/4] capistrano deploy: sass should be executed under bundle exec --- config/deploy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index c7e3e8631..67fae765f 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -41,7 +41,7 @@ namespace :deploy do end task :bundle_static_assets do - run "cd #{current_path} && sass --update public/stylesheets/sass:public/stylesheets" + run "cd #{current_path} && bundle exec sass --update public/stylesheets/sass:public/stylesheets" run "cd #{current_path} && bundle exec jammit" end From 8632c8c40bf27e491a502653356efeecf7e22db6 Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Sat, 4 Feb 2012 17:59:30 +0100 Subject: [PATCH 3/4] capistrano deploy: let the user choose if running svc and svstat with sudo Set svc_sudo to true in deploy_config.yml to use sudo. The default value will be false, so that if the parameter is missing capistrano will behave exactly as before. --- config/deploy.rb | 31 ++++++++++++++++++++++--------- config/deploy/production.rb | 3 +++ config/deploy/staging.rb | 3 +++ config/deploy_config.yml.example | 3 +++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 67fae765f..6191ca171 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -46,7 +46,7 @@ namespace :deploy do end task :restart do - thins = capture "svstat /service/thin*" + thins = capture_svstat "/service/thin*" matches = thins.match(/(thin_\d+):/).captures matches.each_with_index do |thin, index| @@ -54,25 +54,25 @@ namespace :deploy do puts "sleeping for 20 seconds" sleep(20) end - run "svc -t /service/#{thin}" + svc "-t /service/#{thin}" end - run "svc -t /service/resque_worker*" + svc "-t /service/resque_worker*" end task :kill do - run "svc -k /service/thin*" - run "svc -k /service/resque_worker*" + svc "-k /service/thin*" + svc "-k /service/resque_worker*" end task :start do - run "svc -u /service/thin*" - run "svc -u /service/resque_worker*" + svc "-u /service/thin*" + svc "-u /service/resque_worker*" end task :stop do - run "svc -d /service/thin*" - run "svc -d /service/resque_worker*" + svc "-d /service/thin*" + svc "-d /service/resque_worker*" end desc 'Copy resque-web assets to public folder' @@ -93,3 +93,16 @@ after 'deploy:symlink' do deploy.copy_resque_assets end + +def maybe_sudo(cmd) + "#{svc_sudo ? sudo : ''} #{cmd}" +end + +def svc(opts) + run(maybe_sudo("svc #{opts}")) +end + +def capture_svstat(opts) + capture(maybe_sudo("svstat #{opts}")) +end + diff --git a/config/deploy/production.rb b/config/deploy/production.rb index b8cb5dc83..3cddcb429 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -12,3 +12,6 @@ if config['branch'] end set :repository, config['repo'] server config['server'], :app, :web, :db, :primary => true +set :svc_sudo, (config['svc_sudo'] || false) +default_run_options[:pty] = true if svc_sudo + diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index 31108791a..13da68bde 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -12,3 +12,6 @@ if config['branch'] end set :repository, config['repo'] server config['server'], :app, :web, :db, :primary => true +set :svc_sudo, (config['svc_sudo'] || false) +default_run_options[:pty] = true if svc_sudo + diff --git a/config/deploy_config.yml.example b/config/deploy_config.yml.example index 614a68bf5..b3fa899b3 100644 --- a/config/deploy_config.yml.example +++ b/config/deploy_config.yml.example @@ -10,6 +10,8 @@ production: password: 'password' rails_env: 'production' repo: 'git://github.com/diaspora/diaspora.git' + #set svc_sudo to true if you want to run scv and svstat with sudo. default: false + svc_sudo: false staging: server: 'staging.example.com' deploy_to: '/var/www/diaspora' @@ -18,3 +20,4 @@ staging: password: 'password' rails_env: 'staging' repo: 'git://github.com/diaspora/diaspora.git' + svc_sudo: false From 67e2ca44fc6ee7b9fe23c3142967b5bf7c6623d4 Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Sat, 4 Feb 2012 18:11:34 +0100 Subject: [PATCH 4/4] capistrano deploy: fixed multiple thin detection --- config/deploy.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index 6191ca171..d841c3a08 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -47,7 +47,10 @@ namespace :deploy do task :restart do thins = capture_svstat "/service/thin*" - matches = thins.match(/(thin_\d+):/).captures + matches = thins.split("\n").inject([]) do |list, line| + m = line.match(/(thin_\d+):/) + list << m.captures[0] unless m.nil? + end matches.each_with_index do |thin, index| unless index == 0