Rails Deployment with capistrano and start resque workers - ruby-on-rails

I'm using capistrano 3.2.1 with capistrano-resque gem to restart rasque workers on deployment. Always getting this error.
If I start workers manually under current directory on production server it starts fine.
cd /home/azureuser/apps/app_production/current && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.1 /usr/bin/env nohup RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.1 ~/.rbenv/bin/rbenv exec bundle exec rake RACK_ENV=production RAILS_ENV=production QUEUE="mailer" PIDFILE=/home/azureuser/apps/app_production/shared/tmp/pids/resque_work_1.pid BACKGROUND=yes VERBOSE=1 INTERVAL=5 environment resque:work >> log/resque.log 2>> log/resque.log )
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as azureuser#thesend.cloudapp.net: nohup exit status: 127
nohup stdout: Nothing written
nohup stderr: Nothing written
/Library/Ruby/Gems/2.0.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:16:in `rescue in block (2 levels) in execute'
/Library/Ruby/Gems/2.0.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
SSHKit::Command::Failed: nohup exit status: 127

After I worked out that capistrano-rbenv was the problem, I removed that gem from my gemfile and also my capfile.
I then just added the following to my deploy.rb file:
set :default_env, {
PATH: "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH",
RBENV_ROOT: '~/.rbenv',
RBENV_VERSION: '2.2.2'
}
Now capistrano-resque works correctly as does unicorn etc..

I fix this based on the #archfish recommendation on capistrano-resque incompatibility between capistrano-resque and capistrano-rbenv issue. Then you should add or modify the :rbenv_prefix on deploy.rb, like:
set :rbenv_prefix, "env RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
Note: the :rbenv_prefix usually is used like:
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"

Related

capistrano 3 error on rake assets precompile

i find out for days for this error but really stuck and the error capistrano gave were not rellay clear what's wrong:
when the capistrano run this:
$HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile as myapp#myIP
it only said:
Caused by:
SSHKit::Command::Failed: rake exit status: 1
SSHKit::Runner::ExecuteError: Exception while executing as myapp#myIP: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
does anything had this ?
i already put on Capfile
require 'capistrano/rails'
and deploy.rb:
set :conditionally_migrate, true
set :migration_servers, -> { primary(fetch(:migration_role)) }
set :rails_assets_groups, :assets
set :migration_role, :app
set :assets_prefix, 'prepackaged-assets'
set :normalize_asset_timestamps, %w{public/images public/javascripts public/stylesheets}

GemNotFound rake when using whenever in development

I'm getting this one error I don't understand (I'm fairly new to rails) when using the gem 'whenever' in development mode.
What I did was update config/schedule.rb and run
whenever --update-crontab --set environment='development'
crontab -l lists:
* * * * * /bin/bash -l -c 'cd /home/vic/Desktop/WorkflowProject && bundle exec bin/rails runner -e development '\''Task.new2'\'' >> log/whenever.log 2>&1'
at config/schedule.rb
set :output, 'log/whenever.log'
every 1.minute do
runner "Task.new2"
end
at log/whenever.log
bundler: failed to load command: bin/rails (bin/rails)
Bundler::GemNotFound: Your bundle is locked to rake (11.3.0), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of rake (11.3.0) has removed it. You'll need to update your bundle to a different version of rake (11.3.0) that hasn't been removed in order to install.
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:179:in `rescue in specs'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:173:in `specs'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:233:in `specs_for'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:222:in `requested_specs'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/runtime.rb:118:in `block in definition_method'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/runtime.rb:19:in `setup'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler.rb:99:in `setup'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/setup.rb:20:in `<top (required)>'
/home/vic/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/vic/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I would grealy appreciate the help, thank you very much!
Try the below commands.
gem install rubygems-bundler
gem regenerate_binstubs
Ref: this
Are you sure to have bundler installed? Try running bundle install inside your application directory.
If no, see Jayaprakash's answer above.
If yes, try bundle exec whenever --update-crontab --set environment='development'.
Update:
Ahh, missed that you are seeing error when your task executes.
Try this in your config/schedule.rb
env :PATH, ENV['PATH']
set :output, "#{ Whenever.path }/log/whenever.log"
every 1.minute do
runner "Task.new2"
end

Capistrano/Sidekiq task not working

I am using rails 4.0 and ruby 2.3.
I am using following gems for capscript.
capistrano (3.4.0)
capistrano-bundler (1.1.4)
capistrano-rails (1.1.5)
I am using capistrano/sidekiq module for running sidekiq related tasks.
When I am running
cap staging sidekiq:start
I get the following error:
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy#10.50.11.190: sidekiq exit status: 1
sidekiq stdout: Nothing written
sidekiq stderr: Nothing written
SSHKit::Command::Failed: sidekiq exit status: 1
sidekiq stdout: Nothing written
sidekiq stderr: Nothing written
Below is the command which failed on running the above task.
cd /opt/optimus_apps/merchant_tracking/current && /usr/bin/env sidekiq --index 0 --pidfile /opt/optimus_apps/merchant_tracking/shared/server/tmp/pids/sidekiq-0.pid -- environment staging --logfile /opt/optimus_apps/merchant_tracking/shared/server/log/sidekiq.log --config /opt/optimus_apps/merchant_tracking/shared/server/config/sidekiq.yml --daemon
I tried running the above command directly on the staging server with a small change and it worked. I ran the following command.
cd /opt/optimus_apps/merchant_tracking/current/server && /usr/bin/env sidekiq --index 0 --pidfile /opt/optimus_apps/merchant_tracking/shared/server/tmp/pids/sidekiq-0.pid --environment staging --logfile /opt/optimus_apps/merchant_tracking/shared/server/log/sidekiq.log --config /opt/optimus_apps/merchant_tracking/shared/server/config/sidekiq.yml --daemon
I changed the rails path from
/opt/optimus_apps/merchant_tracking/current --> /opt/optimus_apps/merchant_tracking/current/server
The problem is my rails app lies inside current/server folder.
So my question is how can I make sidekiq task to pick current/server folder rather than the current folder?
Thanks in advance.

Still getting gem not found with capistrano

I've been trying to configure my deployment with capistrano for a few weeks now, and it still is not working properly. Every time I deploy to my server I get an error saying a gem is missing, like:
DEBUG [a0e618f0] /home/ec2-user/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/spec_set.rb:92:in `block in materialize'
DEBUG [a0e618f0] :
DEBUG [a0e618f0] Could not find ansi-1.4.3 in any of the sources
DEBUG [a0e618f0] (
DEBUG [a0e618f0] Bundler::GemNotFound
DEBUG [a0e618f0] )
I know how to fix this, simply install the "ansi" gem, but there is a much bigger problem here: why didn't bundler work properly with capistrano??
When I look higher in the output I see:
INFO [1ee9a88e] Running ~/.rvm/bin/rvm ruby-2.0.0-p247 do bundle --gemfile /var/www/html/SparkMyInterest/releases/20131122204608/Gemfile --path /var/www/html/SparkMyInterest/shared/bundle --deployment --quiet --binstubs /var/www/html/SparkMyInterest/shared/bin --without development test on 54.200.196.1
DEBUG [1ee9a88e] Command: cd /var/www/html/SparkMyInterest/releases/20131122204608 && ( RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.0.0-p247 do bundle --gemfile /var/www/html/SparkMyInterest/releases/20131122204608/Gemfile --path /var/www/html/SparkMyInterest/shared/bundle --deployment --quiet --binstubs /var/www/html/SparkMyInterest/shared/bin --without development test )
INFO [1ee9a88e] Finished in 20.132 seconds with exit status 0 (successful).
DEBUG [7d1a9e40] Running if test ! -d /var/www/html/SparkMyInterest/releases/20131122204608; then echo "Directory does not exist '/var/www/html/SparkMyInterest/releases/20131122204608'" 1>&2; false; fi on 54.200.196.1
DEBUG [7d1a9e40] Command: if test ! -d /var/www/html/SparkMyInterest/releases/20131122204608; then echo "Directory does not exist '/var/www/html/SparkMyInterest/releases/20131122204608'" 1>&2; false; fi
DEBUG [7d1a9e40] Finished in 1.291 seconds with exit status 0 (successful).
INFO [a0e618f0] Running ~/.rvm/bin/rvm ruby-2.0.0-p247 do rake assets:precompile on 54.200.196.1
DEBUG [a0e618f0] Command: cd /var/www/html/SparkMyInterest/releases/20131122204608 && ( RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.0.0-p247 do rake assets:precompile )
DEBUG [a0e618f0] /home/ec2-user/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/spec_set.rb:92:in `block in materialize'
DEBUG [a0e618f0] :
DEBUG [a0e618f0] Could not find ansi-1.4.3 in any of the sources
DEBUG [a0e618f0] (
DEBUG [a0e618f0] Bundler::GemNotFound
DEBUG [a0e618f0] )
Clearly it looks like bundler was run (and successful!). What gives?
Here's my cap file:
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
And in my production.rb (I'm deploying with production) at the top I have:
set :stage, :production
set :rails_env, "production"
Any ideas why bundler isn't working? And/ or why it never seems to install all the required gems?
Thank you a million
I've worked through similar issues with rvm involved (required rvm/capistrano) by providing some additional info to capitrano
set :bundle_cmd, '/path/to/project/rvm/bundle'
set :default_shell, :bash
set :rvm_type, :system
set :rvm_ruby_string, release_path
This code was in my stage-specific deploy (e.g., deploy/production.rb). The issue that I had to work around was that the bundle was installed but to the wrong place; could be what you're facing here as well.
FWIW, rvm/capsitrano also let me specify a shell to use when running certain commands within the deploy script. For example, I was using the whenever gem to update my crontab and needed the "rvm_shell" (my specific ruby with gemset) to make this happen from capistrano. The line looks like this:
run "cd #{release_path} && bundle exec whenever -w -s environment=production", shell: fetch(:rvm_shell)

Capistrano deployment, asset pipeline, ruby-debug not found

I'm deploying my Rails 3.2.2, Ruby 1.9.3 app with Capistrano to a Linux server. When I'm running a cap deploy I get this error:
* executing `deploy:assets:precompile'
* executing "cd /var/www/production/releases/20120418090209 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["example.com"]
[example.com] executing command
[example.com] sh -c 'cd /var/www/production/releases/20120418090209 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'
** [out :: example.com] rake aborted!
** [out :: example.com] cannot load such file -- ruby-debug
** [out :: example.com]
** [out :: example.com] (See full trace by running task with --trace)
command finished in 8962ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/production/releases/20120418090209; true"
servers: ["example.com"]
[example.com] executing command
[example.com] sh -c 'rm -rf /var/www/production/releases/20120418090209; true'
command finished in 176ms
failed: "sh -c 'cd /var/www/production/releases/20120418090209 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on example.com
It says, that the ruby-debug gem was not found. But ruby-debug is not inside the production group in my Gemfile:
group :development, :test do
gem "steak"
gem "linecache19", :git => "git://github.com/mark-moseley/linecache", :require => "ruby-debug"
gem "ruby-debug-base19x", "~> 0.11.30.pre4"
gem "ruby-debug19"
gem "rails_best_practices"
gem "ruby_parser"
gem "reek"
gem "flog"
gem "jslint_on_rails", :git => "git://github.com/psionides/jslint_on_rails"
gem "jasmine-rails"
end
Cause the error gets thrown after the rake assets:precompile command, I think it has something todo with Capistrano and the load 'deploy/assets' call inside my Capfile:
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['config/deploy/recipes/*.rb','vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
When I remove this line, everything deploys fine, but (of course) the assets aren't found in production. And, if I run bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile directly on the server (inside the app dir) I get the same error.
So what should I do?
ruby-debug is obsolete. In ruby >= 1.9 you should use excellent debugger gem
see: https://github.com/cldwalker/debugger and http://railscasts.com/episodes/54-debugging-ruby-revised

Resources