I deploying rails project using capistrano 3.0
ror + nginx + unicorn
deploy is so not bad.
but server died during unicorn restart time.
1~2 second died server..
I dont know what i todo..
this is my deploy.rb source..
# -*- encoding : utf-8 -*-
# config valid only for Capistrano 3.1
lock '3.1.0'
require 'unicorn'
#set :whenever_command, "bundle exec whenever"
#require "whenever/capistrano"
set :application, 'projectname'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
# Default deploy_to directory is /var/www/my_app
# set :deploy_to, '/var/www/my_app'
# Default value for :scm is :git
set :scm, :git
set :repo_url, 'git#github.com:gitURL'
# Default value for :format is :pretty
set :branch, 'master'
set :deploy_via, :remote_cache
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
# set :linked_files, %w{config/database.yml}
# Default value for linked_dirs is []
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default value for default_env is {}
set :default_env, { path: "/root/.rbenv/versions/2.1.0/lib/ruby/gems:/root/.rbenv/versions/2.1.0/bin:$PATH" }
#set :current_deploy_path, "DEPLOY_PATH"
# Default value for keep_releases is 5
# set :keep_releases, 5
set :ssh_options, { :forward_agent => true}
set :user, "user"
set :password, "passwod"
namespace :whenever do
task :start do
on roles(:app) do
execute("cd #{fetch :current_deploy_path}")
within release_path do
with rails_env: fetch(:rails_env) do
execute :bundle, 'exec whenever --update-crontab'
end
end
end
end
end
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
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
before 'deploy:assets:precompile', :link_assets
task :link_assets do
on roles(:app), :roles => :app, :except => { :no_release => true } do
execute("ln -fs #{shared_path}/database.yml #{release_path}/config/database.yml")
end
end
#before 'deploy:publishing', :kill_unicorns
task :kill_unicorns do
on roles(:app), in: :sequence, wait: 3 do
execute("if [ -f #{fetch :current_deploy_path}/tmp/pids/unicorn.pid ]; then kill -s QUIT `cat #{fetch :current_deploy_path}/tmp/pids/unicorn.pid`; fi")
end
end
task :make_unicorn do
on roles(:app), in: :sequence, wait: 3 do
execute :mkdir, '-p', "#{fetch :current_deploy_path}/tmp/pids"
execute("cd #{fetch :current_deploy_path}")
execute("if [ -f #{shared_path}/unicorn.pid ]; then kill -s QUIT `cat #{shared_path}/unicorn.pid`; fi")
within release_path do
with rails_env: fetch(:rails_env) do
execute :bundle, 'exec unicorn -D -c config/unicorn.rb -E production'
end
end
execute("cp #{fetch :current_deploy_path}/tmp/pids/unicorn.pid #{shared_path}/unicorn.pid")
end
end
# desc "Update the crontab file"
# task :update_crontab do #, :roles => :db do
# on roles(:app), in: :sequence, wait: 3 do
# execute("cd #{release_path} && bundle exec whenever --update-crontab #{application}")
# end
# end
# after 'deploy:publishing', :kill_unicorns
after 'deploy:publishing', :make_unicorn
after 'deploy:finishing', 'whenever:start'
end
and this is my deploy/production.rb
set :domain, "14.63.165.216"
set :rails_env, "production"
set :current_deploy_path, "/geuinea_pig/priday/current"
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
server '14.63.165.216', user: 'root', roles: %w{web app db}, primary: true#, my_property: :my_value
set :deploy_to, '/geuinea_pig/priday'
set :ssh_options, {
user: 'root', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
forward_agent: false,
#auth_methods: %w(publickey password),
auth_methods: %w(password),
password: 'dPffhdPffh1!'
}
this is deploy log in capistrano log
INFO [193203be] Running /usr/bin/env if [ -f /path/shared/unicorn.pid ]; then kill -s QUIT `cat /path/shared/unicorn.pid`; fi on 14.63.165.216
DEBUG [193203be] Command: if [ -f /path/shared/unicorn.pid ]; then kill -s QUIT `cat /path/shared/unicorn.pid`; fi
#---------------------------------
#THIS TIME DIED SERVER 2~3 second
#---------------------------------
INFO [193203be] Finished in 0.227 seconds with exit status 0 (successful).
DEBUG [05a0c865] Running /usr/bin/env if test ! -d /path/releases/20140706164800; then echo "Directory does not exist '/path/releases/20140706164800'" 1>&2; false; fi on 14.63.165.216
DEBUG [05a0c865] Command: if test ! -d /path/releases/20140706164800; then echo "Directory does not exist '/path/releases/20140706164800'" 1>&2; false; fi
DEBUG [05a0c865] Finished in 0.229 seconds with exit status 0 (successful).
INFO [3cf3c052] Running /usr/bin/env bundle exec unicorn -D -c config/unicorn.rb -E production on 14.63.165.216
DEBUG [3cf3c052] Command: cd /path/releases/20140706164800 && ( PATH=/root/.rbenv/versions/2.1.0/lib/ruby/gems:/root/.rbenv/versions/2.1.0/bin:$PATH RAILS_ENV=production /usr/bin/env bundle exec unicorn -D -c config/unicorn.rb -E production )
INFO [3cf3c052] Finished in 1.061 seconds with exit status 0 (successful).
INFO [07718210] Running /usr/bin/env cp /path/current/tmp/pids/unicorn.pid /path/shared/unicorn.pid on 14.63.165.216
DEBUG [07718210] Command: cp /path/current/tmp/pids/unicorn.pid /path/shared/unicorn.pid
INFO [07718210] Finished in 0.197 seconds with exit status 0 (successful).
I would suggest a slower start on Capistrano, if you're new to it? I find it challenging. In fact, I think you're way beyond me. There are so many little things that can go wrong and the logs/output can be a bit overwhelming that I try some simpler cap tasks. I create a weird directory under the home of my deployer user and then run this:
task :dir_exists do
ask(:dir_to_test, "$home")
on roles(:all) do |host|
if test("[ -d #{fetch(:dir_to_test)} ]")
info "Phew, it's ok, the directory exists!"
else
info "Directory #{fetch(:dir_to_test)} does not exist"
end
end
end
If that runs, at least I know that I'm communicating with the server and can run things. I had big problems at first mostly having to do with the authentication. I didn't get the whole ssh-add thing. Even yesterday I had to run some new commands on my database and it took me a about two hours to figure out that my syntax was complete crap.
Anyway, the more specific you can be about what is going wrong, the more help that will be offered. By the way, do you really have a top-level directory called "/geuinea_pig/friday/current"? If all of this is capistrano, maybe save these files off and start simpler? I say that because my deploy is alot simpler, maybe you don't need all that? Also, won't backtick execution happen on the local machine (you have backtick cat /path/shared/unicorn.pid backtick)?
Anyway, good luck!
Related
I am using Capistrano gem for deploy management of my Ruby on Rails app. Its connected with AWS server, EC2, MySQL Redis. While I am putting my command "cap production deploy" or "cap staging deploy" nothing happens. I just got stuck there.
To add here my SSH key is properly added. And in my AWS security groups, only the authorized IPs are added to have the permission of deploying. My IPs are also added.
But when I add open ports 0.0.0.0/0 in all security groups it allows me to deploy. But I shouldn't add open ports for the sace of application security.
What can be the reason and how to solve these?
screenshot of my console, nothing happens
Below is my deploy.rb file:
SSHKit.config.command_map[:rake] = 'bundle exec rake'
# config valid only for current version of Capistrano
lock '3.8.1'
set :application, 'my_app'
set :repo_url, 'git#gitlab.com:_____'
set :deploy_via, :remote_cache
set :rvm_roles, [:app, :web]
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.4.0'
set :log_level, :debug
set :pty, false
set :linked_files, %w{config/application.yml config/database.yml}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/assets public/uploads}
set :keep_releases, 10
set :whenever_roles, [:web, :app,:db]
set :whenever_identifier, "#{fetch(:application)}_#{fetch(:stage)}"
namespace :deploy do
desc 'restart (upgrade) unicorn server'
task :restart do
invoke 'unicorn:restart'
end
after :finishing, 'deploy:cleanup'
after 'deploy:publishing', 'deploy:restart'
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
within release_path do
execute :rake, 'tmp:cache:clear'
end
end
end
end
namespace :delayed_job do
desc 'List of running delayed job workers'
task :list do
on roles(:all) do |host|
execute :ps, 'aux | grep delayed_job'
end
end
desc 'Stop delayed_job workers forcefully'
task :kill do
on roles(:all) do |host|
execute :kill, "-9 $(ps aux | grep delayed_job | awk '{print $2}')"
end
end
end
task :upload_secret_files do
on roles(:all) do |host|
begin
execute "mkdir -p #{shared_path}/config"
rescue
end
upload! 'config/application.yml', "#{shared_path}/config/application.yml"
upload! 'config/database.yml', "#{shared_path}/config/database.yml"
end
end
task :log do
on roles(:all) do |host|
execute "tail -f #{current_path}/log/#{fetch(:rails_env)}.log"
end
end
desc 'Invoke a rake command on the remote server'
task :invoke, [:command] => 'deploy:set_rails_env' do |task, args|
on primary(:app) do
within current_path do
with rails_env: fetch(:rails_env) do
rake args[:command]
end
end
end
end
I was struggling with exactly the same issue and spent several hours. Didn't get what is the issue related to. It just started working after I reboot my local OS
I have a simple rails app that I am trying to deploy to a production server using Capistrano, but it appears to fail when trying to create the puma.pid.
When I check the the puma.access.log I see the following,
/home/capin/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/rfc3986_parser.rb:66:in `split': bad URI(is not URI?): unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock (URI::InvalidURIError)
from /home/capin/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/rfc3986_parser.rb:72:in `parse'
from /home/capin/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/common.rb:226:in `parse'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/binder.rb:85:in `block in parse'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/binder.rb:84:in `each'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/binder.rb:84:in `parse'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/runner.rb:119:in `load_and_bind'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/single.rb:79:in `run'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/cli.rb:215:in `run'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/bin/puma:10:in `<top (required)>'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/bin/puma:23:in `load'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/bin/puma:23:in `<main>'
Does anybody know why puma would display this error? I can post more configuration files if need be too.
The console output when running the deploy command,
INFO [5680e746] Finished in 2.087 seconds with exit status 0 (successful).
DEBUG [d53f0457] Running /usr/bin/env if test ! -d /home/capin/apps/Tshirt/current; then echo "Directory does not exist '/home/capin/apps/Tshirt/current'" 1>&2; false; fi on youtee.io
DEBUG [d53f0457] Command: if test ! -d /home/capin/apps/Tshirt/current; then echo "Directory does not exist '/home/capin/apps/Tshirt/current'" 1>&2; false; fi
DEBUG [d53f0457] Finished in 0.296 seconds with exit status 0 (successful).
DEBUG [54524c04] Running /usr/bin/env [ -f /home/capin/apps/Tshirt/shared/tmp/pids/puma.pid ] on youtee.io
DEBUG [54524c04] Command: [ -f /home/capin/apps/Tshirt/shared/tmp/pids/puma.pid ]
DEBUG [54524c04] Finished in 0.310 seconds with exit status 1 (failed).
DEBUG [287a3b10] Running /usr/bin/env if test ! -d /home/capin/apps/Tshirt/releases; then echo "Directory does not exist '/home/capin/apps/Tshirt/releases'" 1>&2; false; fi on youtee.io
DEBUG [287a3b10] Command: if test ! -d /home/capin/apps/Tshirt/releases; then echo "Directory does not exist '/home/capin/apps/Tshirt/releases'" 1>&2; false; fi
DEBUG [287a3b10] Finished in 0.217 seconds with exit status 0 (successful).
INFO [5a813829] Running /usr/bin/env echo "Branch master (at 538f125)
deployed as release 20160101233746 by capin" >> /home/capin/apps/Tshirt/revisions.log on youtee.io
DEBUG [5a813829] Command: echo "Branch master (at 538f125) deployed as release 20160101233746 by capin" >> /home/capin/apps/Tshirt/revisions.log
INFO [5a813829] Finished in 0.248 seconds with exit status 0 (successful).
production.rb
# server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:
# server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
# server 'db.example.com', user: 'deploy', roles: %w{db}
server 'youtee.io', port: 4321, roles: [:web, :app, :db], primary: true
set :rvm_ruby_string, '2.2.1'
set :repo_url, 'git#bitbucket.org:ipatch/tshirt.git'
set :application, 'Tshirt'
set :user, 'capin'
set :puma_threads, [4, 16]
set :puma_workers, 0
# Don't change these unless you know what you're doing
set :pty, true
set :use_sudo, false
set :stage, :production
set :deploy_via, :remote_cache
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
# files we want symlinking to specific entries in shared.
set :linked_files, %w{config/database.yml config/secrets.yml}
# see this SO answer, http://stackoverflow.com/a/32011351/708807
# set :linked_dirs, fetch(:linked_dirs, []).push('public/uploads')
set :puma_bind, "tcp://0.0.0.0:9294"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to false when not using ActiveRecord
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:app) do
# preserve uploaded files through Capistrano deployments
# ln -n = ln -h, which if target dir is a sym link don't follow
# ln -f, if already linked unlink so new link can be created
# ln -s, creates a symlink
# execute :ln, "-nfs #{shared_path}/public/uploads/store #{release_path}/public/uploads/store"
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
end
# role-based syntax
# ==================
# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.
# role :app, %w{deploy#example.com}, my_property: :my_value
# role :web, %w{user1#primary.com user2#additional.com}, other_property: :other_value
# role :db, %w{deploy#example.com}
# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.
# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
set :ssh_options, {
keys: %w(/Users/capin/.ssh/id_rsa),
forward_agent: true,
auth_methods: %w(publickey password)
# port: 4321,
}
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
shared/puma.rb
#!/usr/bin/env puma
directory '/home/capin/apps/Tshirt/current'
rackup "/home/capin/apps/Tshirt/current/config.ru"
environment 'production'
pidfile "/home/capin/apps/Tshirt/shared/tmp/pids/puma.pid"
state_path "/home/capin/apps/Tshirt/shared/tmp/pids/puma.state"
stdout_redirect '/home/capin/apps/Tshirt/current/log/puma.error.log', '/home/capin/apps/Tshirt/current/log/puma.access.log', true
threads 4,16
bind 'unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock'
workers 0
preload_app!
on_restart do
puts 'Refreshing Gemfile'
ENV["BUNDLE_GEMFILE"] = "/home/capin/apps/Tshirt/current/Gemfile"
end
on_worker_boot do
ActiveSupport.on_load(:active_record) do
ActiveRecord::Base.establish_connection
end
end
Looks like mistake in your puma/capistrano configuration file. I think you put the line unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock into single quotas instead of double and string interpolation is not working :)
UPDATE:
check your puma_bind value, should be
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
in double quotas
here is my deployment.rb file.
# config valid only for current version of Capistrano
lock '3.4.0'
set :stage, 'production'
set :application, "gobgob-ror"
set :repo_url, 'git#github.com:narhamah/gobgob-ror.git'
# 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, '/home/ubuntu/gobgob-ror'
# Default value for :scm is :git
set :scm, :git
set :branch, "master"
#set :user, "ubuntu"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :remote_cache
set :ssh_options, { user: 'ubuntu', :forward_agent => true, :port => 22, keys: ["#{ENV['HOME']}/.ssh/id_rsa"]}
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
set :pty, true
server "xx.xx.xxx.xxx", roles: [:app, :web, :db], :primary => true
set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets}
# Default value for :linked_files is []
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
set :keep_releases, 5
namespace :deploy do
desc "Start the application"
task :start do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{fetch(:stage)}.log 2>&1 &", :pty => false
end
end
desc "Stop the application"
task :stop do
on roles => :app do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state stop"
end
end
desc "Restart the application"
task :restart do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state restart"
end
end
desc "Status of the application"
task :status do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state stats"
end
end
end
after "deploy", "deploy:restart"
after "deploy", "deploy:cleanup"
Now I did bundle exec cap production deploy. And after huge log I got the below error.
DEBUG [cced60a1] bash: bundle: command not found
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host <ip-snipped>: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written
SSHKit::Command::Failed: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written
Tasks: TOP => deploy:restart
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host <ip-snipped>: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written
[arup#gobgob-ror (master)]$
Looks like the bundler gem is not installed on your server. It should be installed and the bundle executable should be available in $PATH.
Try executing the bundle --version directly on the server to ascertain that bundler is actually missing.
If that is case, install the bundler gem and you should be good to go. Or to actually keep things automated you can define a capistrano task to check if the bundle executable is available or not and install the bundler gem if it is not available. You can execute this task before the bundler:install task.
UPDATE : If you are using some ruby manager like rvm or chruby or anything like that, the bundle executable might not be available to your Capistrano deploy task. In that case you have to make sure your deploy task gets a login shell so that all those shell scripts are executed.
Here is what I have now which resolved the issue. I got help from Rustam A. Gasanov to make it working. Thanks a lot!!
deploy.rb
# config valid only for current version of Capistrano
lock '3.4.0'
set :stage, 'production'
set :application, "gobgob-ror"
set :repo_url, 'git#github.com:narhamah/gobgob-ror.git'
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.2.2#gobgob'
set :rvm_binary, '~/.rvm/bin/rvm'
# 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, '/home/ubuntu/gobgob-ror'
# Default value for :scm is :git
set :scm, :git
set :branch, "master"
#set :user, "ubuntu"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :remote_cache
set :ssh_options, { user: 'ubuntu', :forward_agent => true, :port => 22, keys: ["#{ENV['HOME']}/.ssh/id_rsa"]}
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
set :pty, true
server "xx.xx.xxx.xxx", roles: [:app, :web, :db], :primary => true
set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets}
# Default value for :linked_files is []
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
set :keep_releases, 5
namespace :deploy do
desc "Start the application"
task :start do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{fetch(:stage)}.log 2>&1 &", :pty => false
end
end
desc "Stop the application"
task :stop do
on roles => :app do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state stop"
end
end
desc "Restart the application"
task :restart do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state restart"
end
end
desc "Status of the application"
task :status do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state stats"
end
end
end
after "deploy", "deploy:restart"
after "deploy", "deploy:cleanup"
Last output which confirmed it works..
INFO [12d4a428] Running /usr/bin/env cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.2.2#gobgob do bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart on xx.xx.xxx.xxx
DEBUG [12d4a428] Command: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.2.2#gobgob do bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart
DEBUG [12d4a428] Command restart sent success
DEBUG [12d4a428]
INFO [12d4a428] Finished in 1.379 seconds with exit status 0 (successful).
[arup#gobgob-ror (master)]$
I am trying to use capistrano (for the first time) to deploy my rails app. First the essentials, I am using:
ruby 1.9.3p362
Rails 3.2.13
rvm 1.24.7
Capistrano 3.0.1
Phusion Passenger 4.0.26
Ubuntu 12.04 LTS
I get the following error when attempting to run cap production deploy
DEBUG [679a47be] fatal: No remote configured to list refs from.
My full cap production deploy output is included below
INFO [488ba755] Running /usr/bin/env mkdir -p /tmp/AppName/ on sub.example.com
DEBUG [488ba755] Command: /usr/bin/env mkdir -p /tmp/AppName/
INFO [488ba755] Finished in 1.730 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/AppName/git-ssh.sh 0.0%
INFO Uploading /tmp/AppName/git-ssh.sh 100.0%
INFO [c895f068] Running /usr/bin/env chmod +x /tmp/AppName/git-ssh.sh on sub.example.com
DEBUG [c895f068] Command: /usr/bin/env chmod +x /tmp/AppName/git-ssh.sh
INFO [c895f068] Finished in 0.217 seconds with exit status 0 (successful).
DEBUG [679a47be] Running /usr/bin/env git ls-remote on sub.example.com
DEBUG [679a47be] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/AppName/git-ssh.sh /usr/bin/env git ls-remote )
DEBUG [679a47be] fatal: No remote configured to list refs from.
DEBUG [679a47be] Finished in 1.775 seconds with exit status 128 (failed).
Gemfile
# Deploy with Capistrano
gem 'capistrano', '~> 3.0.0'
gem 'capistrano-rails', '~> 1.1.0'
gem 'rvm1-capistrano3', require: false
Capfile
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
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 }
deploy.rb
I have altered this file to add my git url, the app name, the deploy_to path, and the tasks inside task :restart as directed to restart Phusion Passenger.
set :application, 'AppName'
set :deploy_to, '/var/www/appname'
set :repository, "git#github.com:username/appname.git" # Your clone URL
set :scm, "git"
set :user, "my-github-deploy-user" # The server's user for deploys
set :scm_passphrase, "correct-password" # The deploy user's password
set :branch, "master"
set :deploy_via, :remote_cache
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
set :ssh_options, {
verbose: :debug
}
set :format, :pretty
set :log_level, :debug
# set :pty, true
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# set :keep_releases, 5
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
# task :start do ; end
# task :stop do ; end
# task :restart, :roles => :app, :except => { :no_release => true } do
# run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
# end
end
end
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
after :finishing, 'deploy:cleanup'
end
I tried to included all necessary information, please let me know if there is anything else I can add, thanks for any help you can provide!
In Capistrano 3, you use repo_url instead of repository
So in your deploy.rb, try replacing
set :repository, "git#github.com:username/appname.git" # Your clone URL
with
set :repo_url, "https://github.com/username/appname.git" # Your clone URL
Hopefully this helps.
Update: The ssh URL needs a key; the https URL does not. It's worked for me.
"rake assets:precompile" and "cap deploy" consume extremely high amount of time whenever I call it (usually more then an hour). Sometimes deploy hang at all.
I use Rails 3.2.13, Ruby 1.9.3, OSX and Backbone's Chaplin Framework for frontend.
How can I speed up assets precompile and deploy task and what can cause such freezing?
My deploy.rb config:
# -*- encoding : utf-8 -*-
require 'bundler/capistrano'
load 'deploy/assets'
set :application, "eyelashes"
set :rails_env, "production"
set :repository, "git#github.com:eyelasher/repo.git"
set :scm, :git
set :deploy_via, :checkout
set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true
server "75.223.145.3", :app, :web, :db, :primary => true
set :bundle_without, [:test]
set :user, 'deployer'
set :deploy_to, "/home/deployer/eyelasher"
set :branch, "master" unless exists?(:branch)
set :use_sudo, false
set :rvm_type, :user
set :rvm_ruby_string, :local
set :deploy_via, :checkout
before 'deploy:setup', 'rvm:create_gemset'
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
after "deploy", "deploy:migrate"
after "deploy", "deploy:cleanup"
require 'rvm/capistrano'
require 'thinking_sphinx/deploy/capistrano'
#after 'deploy:update_code', :roles => :app do
#run "rm -f #{current_release}/config/database.yml"
#run "ln -s #{deploy_to}/shared/config/database.yml #{current_release}/config/database.yml"
#end
namespace :deploy do
task :restart do
run "if [ -f #{unicorn_pid} ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D; fi"
end
task :start do
run "cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D;"
end
task :stop do
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
end
end
# Thinking Sphinx typing shortcuts
namespace :ts do
task :conf do
thinking_sphinx.configure
end
task :in do
thinking_sphinx.index
end
task :start do
thinking_sphinx.start
end
task :stop do
thinking_sphinx.stop
end
task :restart do
thinking_sphinx.restart
end
task :rebuild do
thinking_sphinx.rebuild
end
end
# http://github.com/jamis/capistrano/blob/master/lib/capistrano/recipes/deploy.rb
# :default -> update, restart
# :update -> update_code, symlink
namespace :deploy do
desc "Link up Sphinx's indexes."
task :symlink_sphinx_indexes, :roles => [:app] do
run "ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx"
end
task :activate_sphinx, :roles => [:app] do
symlink_sphinx_indexes
thinking_sphinx.configure
#thinking_sphinx.stop
#thinking_sphinx.start
end
task :copy_images do
run "cp -R #{shared_path}/public/images #{release_path}/public/images"
end
before 'deploy:update_code', 'thinking_sphinx:stop'
after 'deploy:update_code', 'deploy:activate_sphinx'
after 'deploy:update_code', 'deploy:copy_images'
end
Maybe I can speedup somehow by making changes in deploy configuration?
If you are deploying to a memory constrained VPS that sounds plausible. I'd recommend precompiling the assets on a a faster machine and checking them in to your repository.
There are various Gems and packages for speeding up asset precompilation by parallesing them, however in your situation that will likely make things MUCH worse!