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.
Related
I have a Rails 5 API with Sidekiq and capistrano-sidekiq that has been happily working fine for the last few months.
The other day, Sidekiq stopped processing jobs. Checking the logs, I saw
bundler: failed to load command: sidekiq (/home/user/project/shared/bundle/ruby/2.2.0/bin/sidekiq)
SignalException: SIGHUP
/home/user/project/shared/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/module/attribute_accessors.rb:119:in `<class:Module>'
/home/user/project/shared/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/module/attribute_accessors.rb:6:in `<top (required)>'
... (snip)
Whenever I try to start up Sidekiq, the above appears in the log. It was shut down using the quiet command (USR1) and exited properly.
INFO: Received USR1, no longer accepting new work
I'm using Capistrano to deploy, which has worked fine until this happened. This is the command Capistrano used to start Sidekiq:
INFO [2aac3b89] Running $HOME/.rbenv/bin/rbenv exec bundle exec sidekiq --index 0 --pidfile /home/user/project/shared/tmp/pids/sidekiq-0.pid --environment production --logfile /home/user/project/shared/log/sidekiq.log --daemon as user#xxx.xxx.xxx.xxx
DEBUG [2aac3b89] Command: cd /home/user/project/current && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.2.3" ; $HOME/.rbenv/bin/rbenv exec bundle exec sidekiq --index 0 --pidfile /home/user/project/shared/tmp/pids/sidekiq-0.pid --environment production --logfile /home/user/project/shared/log/sidekiq.log --daemon )
INFO [2aac3b89] Finished in 1.176 seconds with exit status 0 (successful).
What is going on? And how can I ensure it doesn't happen in future?
In capistrano, I had :pty set to true. I guess it was killing the process before it had a chance to start up. I still am not sure why this is an issue now, but setting :pty to false seems to have done the trick.
When deploying our API (which doesn't use assets at all), it hangs for about 5 minutes on this line:
DEBUG [985661f8] cannot access /var/www/api.staging/releases/20160208111413/public/assets/.sprockets-manifest*
DEBUG [985661f8] : No such file or directory
We have already disabled assets in config/application.rb:
config.assets.enabled = false
What else needs to be done? We're using these versions:
capistrano (3.4.0)
capistrano-bundler (1.1.4)
capistrano-rails (1.1.3)
capistrano-rails-collection (0.0.3)
Capistrano log:
INFO [42c93c96] Running /usr/local/rvm/bin/rvm 2.1.0#appyapi.staging do bundle exec rake assets:precompile as deploy#139.162.4.97
DEBUG [42c93c96] Command: cd /var/www/appyapi.staging/releases/20160223041856 && ( RAILS_ENV=staging /usr/local/rvm/bin/rvm 2.1.0#appyapi.staging do bundle exec rake assets:precompile )
INFO [42c93c96] Finished in 279.004 seconds with exit status 0 (successful).
DEBUG [f2410fde] Running /usr/bin/env if test ! -d /var/www/appyapi.staging/releases/20160223041856; then echo "Directory does not exist '/var/www/appyapi.staging/releases/20160223041856'" 1>&2; false; fi as deploy#139.162.4.97
DEBUG [f2410fde] Command: if test ! -d /var/www/appyapi.staging/releases/20160223041856; then echo "Directory does not exist '/var/www/appyapi.staging/releases/20160223041856'" 1>&2; false; fi
DEBUG [f2410fde] Finished in 0.081 seconds with exit status 0 (successful).
INFO [fd9b639a] Running /usr/bin/env mkdir -p /var/www/appyapi.staging/releases/20160223041856/assets_manifest_backup as deploy#139.162.4.97
DEBUG [fd9b639a] Command: cd /var/www/appyapi.staging/releases/20160223041856 && /usr/bin/env mkdir -p /var/www/appyapi.staging/releases/20160223041856/assets_manifest_backup
INFO [fd9b639a] Finished in 0.078 seconds with exit status 0 (successful).
DEBUG [462a5734] Running /usr/bin/env ls /var/www/appyapi.staging/releases/20160223041856/public/assets/.sprockets-manifest* as deploy#139.162.4.97
DEBUG [462a5734] Command: cd /var/www/appyapi.staging/releases/20160223041856 && /usr/bin/env ls /var/www/appyapi.staging/releases/20160223041856/public/assets/.sprockets-manifest*
DEBUG [462a5734] ls: cannot access /var/www/appyapi.staging/releases/20160223041856/public/assets/.sprockets-manifest*
DEBUG [462a5734] : No such file or directory
DEBUG [462a5734] Finished in 0.079 seconds with exit status 2 (failed).
OK, first it is important to know that the "No such file or directory" error is benign. Capistrano executes certain commands as tests and takes different code paths based on the results, and it is completely normal that some of those tests result in failures. Unless Capistrano raises an exception, you can safely ignore these "errors".
Second, it seems that rake assets:precompile is being run even though you are not using the asset pipeline, and therefore have no use for it. I'm surprised this step could take so long if you don't have any assets, but let's leave that for another discussion.
The quick solution is to not include the asset pipeline steps of the capistrano-rails plugin. As explained in the README, you can do this by including only the steps you need.
So:
# Put these in your Capfile
require "capistrano/bundler"
require "capistrano/rails/migrations"
# REMOVE these lines so that asset pipeline steps are excluded
# require "capistrano/rails"
# require "capistrano/rails/assets"
I've seen this issue in a few other questions/Github issues, but they haven't been able to shed enough light to lead to the solution.
The error:
bash: bundle: command not found
SSHKit::Runner::ExecuteError: Exception while executing as my-user#my-IP-address: cd /path-to-my-app/current ; bundle exec unicorn -D -c config/unicorn.rb -E production exit status: 127
cd /path-to-my-app/current ; bundle exec unicorn -D -c config/unicorn.rb -E production stdout: Nothing written
cd /path-to-my-app/current ; bundle exec unicorn -D -c config/unicorn.rb -E production stderr: bash: bundle: command not found
I'm using the latest version of Capistrano on my rails app. Specifically, it's a Rails 4.2.0 app with the gems capistrano-rails and capistrano-rvm.
I have a pretty standard config/unicorn.rb file, which is how I start unicorn while logged into my server. I first kill the current PID with:
kill -9 PID
Then I start unicorn with:
bundle exec unicorn -D -c /path-to-my/config/unicorn.rb -E production
This works great, but obviously I need capistrano to do that, so I essentially have those tasks in my deploy.rb file, however I get that error mentioned above. Here are the two tasks I have in deploy.rb:
namespace :deploy do
namespace :unicorn do
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute "kill -s USR2 `cat /path-to-my/tmp/pids/app-name.pid`"
end
end
desc 'Start unicorn'
task :start do
on roles(:app), in: :sequence, wait: 5 do
execute "cd #{current_path} ; bundle exec unicorn -D -c config/unicorn.rb -E production"
end
end
end
end
I have a similar task to restart DelayedJob, which throws the same error. The command is execute "cd #{current_path} ; RAILS_ENV=production bin/delayed_job -n2 restart". Like I mentioned above, when logged into the server with my user (same user I use for Capistrano), all of these tasks work as expected.
Every other built-in task works great with Capistrano, like precompiling assets, migrating my database, etc. It is the custom tasks I've added that are getting the error.
Let me know if I can add anything to help solve the problem.
Look at output of Capistrano carefully. Such commands as bundle assets:precompile makes initialization of required ruby version:
cd /<app path>/20150301211440 && ( RAILS_ENV=staging /usr/local/rvm/bin/rvm 2.1.5 do bundle exec rake assets:precompile )
Seems like you don't do it. So, probably you a using system ruby by default and it doesn't have a bundler gem.
Try to specify ruby version use RVM in your commands too. I think it should fix your problem.
Capistrano 3.0 deploy failed on rails 3.2 because there is not manfest.*json with the following error.
However, there is manifest.yml which is expected for rails 3.2 while rails 4.0 expects manifest.json. any idea why this happening or how i can go about it.
INFO [b38cf17e] Running /usr/bin/env cp /var/www/html/webapp/releases/20140102161642/public/assets/manifest*.json /var/www/html/webapp/releases/20140102161642/assets_manifest_backup.json on 208.68.39.56
DEBUG [b38cf17e] Command: cd /var/www/html/webapp/releases/20140102161642 && /usr/bin/env cp /var/www/html/webapp/releases/20140102161642/public/assets/manifest*.json /var/www/html/webapp/releases/20140102161642/assets_manifest_backup.json
cap aborted!
cp stdout: Nothing written
cp stderr: Nothing written
Thank you in advance..
So I am attempting to get a capistrano deployment setup with an nginx/unicorn server, using RVM.
The deploy works, but when I attempt to interact with unicorn via capistrano i get an error like:
[~/source/quibbler/config]
$ cap unicorn:start
* executing `unicorn:start'
* executing "cd /u/apps/quibbler/current && bundle exec unicorn_rails -c /u/apps/quibbler/current/config/unicorn-production.rb -E production -D"
servers: ["wwwtestvm.whf.app"]
[wwwtestvm.whf.app] executing command
** [out :: wwwtestvm.whf.app] Could not find rake-0.9.2 in any of the sources
command finished in 553ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'ruby-1.9.2-p290#quibbler' -c 'cd /u/apps/quibbler/current && bundle exec unicorn_rails -c /u/apps/quibbler/current/config/unicorn-production.rb -E production -D'" on wwwtestvm.whf.app
I have searched the interwebs all night and can not find the solution. If I copy paste the command into my shell it works so I am 99% sure it has to do with the RVM environment not being correct.
I have created a gist of my deploy and unicorn configs:
https://gist.github.com/1375736#file_deploy.rb
https://gist.github.com/1375736#file_unicorn_production.rb
Any help or guidance would be appreciated.
Thanks to sannankhalid answer on this other question i was able to resolve it.
Short answer: add rake to your Gemfile, make sure you run bundle install so your Gemfile.lock gets updated, then deploy to your server, ayay!