I am a beginner with Ruby and Rails, and I'm having an issue deploying my Rails app to my localhost. The issue seems that there is some default config value somewhere, referencing example.com.
deploy#localhost:/home/user/code/project$ cap production deploy
DEBUG[8b34c0bb] Running /usr/bin/env [ -d ~/.rvm ] on 127.0.0.1
DEBUG[8b34c0bb] Command: [ -d ~/.rvm ]
DEBUG[b62cfdef] Running /usr/bin/env [ -d ~/.rvm ] on example.com
DEBUG[b62cfdef] Command: [ -d ~/.rvm ]
cap aborted!
It fails trying to deploy to example.com (obviously)
Where is this config value (file?) so I can get rid of it? I just deploy using Capistrano to localhost!
EDIT config/deploy.rb
set :application, 'project'
set :repo_url, 'git#github.com:excid3/myapp.git'
set :deploy_to, '/home/deploy/ninja'
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :finishing, 'deploy:cleanup'
end
The :repo_url might be bogus.. not sure if that is affecting it.
The file is config/deploy.rb inside rails root folder. That is where the default configuration should be. It is usually something like
server "www.example.com", :app, :web, :db, :primary => true
Related
I have set up my rails app for use with rpush. It works fine locally in development using rpush start. But now I want to deploy it to my EC2 server using capistrano-2.15.5.
Part of my deploy.rb:
after "deploy:stop", "delayed_job:stop"
after "deploy:stop", "rpush:stop"
after "deploy:start", "delayed_job:start"
after "deploy:start", "rpush:start"
after "deploy:restart", "delayed_job:restart"
after "deploy:restart", "rpush:restart"
namespace :rpush do
%w[start stop restart].each do |command|
desc "#{command} rpush deamon"
task command, roles: :app, except: {no_release: true} do
run "cd #{deploy_to}/current && bundle exec rpush #{command}"
end
end
end
Now, the problems
it starts in development environment. I tried to understand this page that tells me how to do it, but I could not.
I do not know whether the pid is stored in the /current dir or /shared dir. It should be in the shared so that the file persists between deploys
If anyone has done this (even in a different way) please tell me how to.
Or, how can I fix my cap recipe and /initializers/rpush
For Capistrano 3:
after :finished, :restart_rpush do
on roles(:web) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :bundle, :exec, "rpush stop -e #{fetch(:rails_env)}"
execute :bundle, :exec, "rpush start -e #{fetch(:rails_env)}"
end
end
end
end
Then check that tmp and other directories is linked correctly:
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/uploads}
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!
We are relatively new to using chef to deploy our applications. Currently, an odd issue we are experiencing and have yet to find a solution for relates to our bin/passenger configuration file. For some reason when the server is constructed with chef it does not exist or chef is not creating it. Maybe capistrano is not creating it... We are a bit dumbfounded by this one.
As you can see from the attached image, we know the file is not there. All of our current scripts match 4 other servers that are running successfully but for some reason this new build will not create the file. Or TBH, we are completely missing some steps. It has been some very long nights trying to get this going.
We used chef to build the server and we are using capistrano to deploy to the box
Anyone have any thoughts? Need more information? Pointers?
Our current config/deploy.rb file:
set :application, 'digest'
set :scm, :git
set :repo_url, '{omitted private repo}'
set :branch, 'experiment/cap'
set :deploy_to, '/home/apps/api'
set :deploy_via, :remote_cache
set :user, 'deploy'
set :use_sudo, false
set :rbenv_type, :system
set :rbenv_ruby, '2.1.0'
set :rbenv_path, '/opt/rbenv'
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute "mkdir -p #{release_path}/tmp ; touch #{release_path}/tmp/restart.txt"
end
end
desc 'Create application symlinks'
task :symlinks do
on roles(:app), in: :sequence, wait: 5 do
execute "rm #{release_path}/config/database.yml"
execute "ln -s #{shared_path}/config/database.yml #{release_path}/config/database.yml"
execute "ln -s #{shared_path}/config/secrets.yml #{release_path}/config/secrets.yml"
execute "ln -s #{shared_path}/bin/passenger #{release_path}/bin/passenger"
end
end
after :finishing, 'deploy:cleanup'
after 'deploy:updated', 'deploy:symlinks'
end
namespace :setup do
desc 'Copy the secrets.yml and database.yml files'
task config: [ 'config/secrets.yml', 'config/database.yml' ] do |t|
on roles(:all) do
execute "mkdir -p #{shared_path}/config"
t.prerequisites.each do |file|
upload! file, "#{shared_path}/config"
end
end
end
end
In our config/deploy/staging.rb file:
set :stage, :staging
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
role :app, %w{deploy#208.94.36.146}
role :web, %w{deploy#208.94.36.146}
set :rails_env, "staging"
Our staging server bin folder:
You can see the application is making it to the box with the current releases setup:
Our current application on the server:
Our current application config directory:
I'm assuming passenger isn't in the Gemfile which is would cause the binstub to not get created. Is that the issue?
i am deploying with capistrano and I am strugg;ling to find out why it will not run migrations when I try to deploy the site.
here is the whole error:
WARN [SKIPPING] No Matching Host for /usr/bin/env if test ! -d /home/deploy/forge_staging/releases/20140319132005; then echo "Directory does not exist '/home/deploy/forge_staging/releases/20140319132005'" 1>&2; false; fi
WARN [SKIPPING] No Matching Host for bundle exec rake db:migrate
heres my setup:
deploy.rb
lock '3.1.0'
server "xxx.xxx.xxx.xxx"
set :application, "ForgeAndCo"
set :scm, "git"
set :repo_url, "my-repo"
# set :scm_passphrase, ""
set :user, "deploy"
set :use_sudo, false
set :ssh_options, {
forward_agent: true,
port: 14439
}
# files we want symlinking to specific entries in shared.
set :linked_files, %w{config/database.yml}
# dirs we want symlinking to shared
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
SSHKit.config.command_map[:rake] = "bundle exec rake" #8
SSHKit.config.command_map[:rails] = "bundle exec rails"
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
set :keep_releases, 20
namespace :deploy do
desc 'Restart passenger without service interruption (keep requests in a queue while restarting)'
task :restart do
on roles(:app) do
execute :touch, release_path.join('tmp/restart.txt')
unless execute :curl, '-s -k --location localhost | grep "Forge" > /dev/null'
exit 1
end
end
end
after :finishing, "deploy:cleanup"
end
# start new deploy.rb stuff for the beanstalk repo
staging.rb
role :app, %w{deploy#xxx.xxx.xxx.xxx}
role :web, %w{deploy#xxx.xxx.xxx.xxx}
role :db, %w{deploy#xxx.xxx.xxx.xxx}
# 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 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
set :stage, :staging
server "xxx.xxx.xxx.xxx", user: "deploy", roles: %w{web app db}
set :deploy_to, "/home/deploy/forge_staging"
set :rails_env, 'staging' # If the environment differs from the stage name
set :migration_role, 'migrator' # Defaults to 'db'
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
Is this an issue with roles?
remove from deploy.rb: (add capistrano-bundler and require it in the Capfile)
server "xxx.xxx.xxx.xxx"
SSHKit.config.command_map[:rake] = "bundle exec rake"
SSHKit.config.command_map[:rails] = "bundle exec rails"
set :user, "deploy" # you have it in staging.rb
set :use_sudo, false # not used in cap3
remove from staging.rb:
role :app, %w{deploy#xxx.xxx.xxx.xxx}
role :web, %w{deploy#xxx.xxx.xxx.xxx}
role :db, %w{deploy#xxx.xxx.xxx.xxx}
set :migration_role, 'migrator' # <= this is why you got the error
PS: edit your question and replace the ip with xxx.
Having setup capistrano on my rails app I was deploying okay I then went and changed some css values on my local site. This was fine but then when I went to deploy my site with cap staging deploy it started to do its normal routine tasks just fine but when it came to capistrano's precompile task for assets it failed. I have managed to source where it is going wrong on the capistrano area and thats here:
task :backup_manifest do
on roles(fetch(:assets_roles)) do
within release_path do
execute :cp,
release_path.join('public', fetch(:assets_prefix), 'manifest*'),
release_path.join('assets_manifest_backup')
end
end
end
task :restore_manifest do
on roles(fetch(:assets_roles)) do
within release_path do
source = release_path.join('assets_manifest_backup')
target = capture(:ls, release_path.join('public', fetch(:assets_prefix),
'manifest*')).strip
if test "[[ -f #{source} && -f #{target} ]]"
execute :cp, source, target
else
msg = 'Rails assets manifest file (or backup file) not found.'
warn msg
fail Capistrano::FileNotFound, msg
end
end
end
end
It fails here where you have within release_path do as thats in the stack trace but I do not know why it does that as i have not changed any tasks at all just ccs tweaks.
Here are my deployment settings for capistrano:
deploy.rb
lock '3.1.0'
server "188.226.182.102"
set :application, "ForgeAndCo"
set :scm, "git"
set :repo_url, "git#made-by-mark.beanstalkapp.com:/made-by-mark/forge.git"
# set :scm_passphrase, ""
set :user, "deploy"
set :use_sudo, false
set :ssh_options, {
forward_agent: true,
port: 14439
}
set :assets_prefix, 'prepackaged-assets'
# files we want symlinking to specific entries in shared.
set :linked_files, %w{config/database.yml}
# dirs we want symlinking to shared
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
SSHKit.config.command_map[:rake] = "bundle exec rake" #8
SSHKit.config.command_map[:rails] = "bundle exec rails"
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
set :keep_releases, 20
namespace :deploy do
desc 'Restart passenger without service interruption (keep requests in a queue while restarting)'
task :restart do
on roles(:app) do
execute :touch, release_path.join('tmp/restart.txt')
unless execute :curl, '-s -k --location localhost | grep "Forge" > /dev/null'
exit 1
end
end
end
end
after 'deploy:publishing', 'deploy:restart'
deploy/staging.rb
role :app, %w{deploy#188.226.182.102}
role :web, %w{deploy#188.226.182.102}
role :db, %w{deploy#188.226.182.102}
# 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 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
set :stage, :staging
server "188.226.182.102", user: "deploy", roles: %w{web app db}
set :deploy_to, "/home/deploy/forge_staging"
set :rails_env, 'staging' # If the environment differs from the stage name
set :migration_role, 'migrator' # Defaults to 'db'
set :assets_roles, [:web, :app] # Defaults to [:web]
set :assets_prefix, 'prepackaged-assets' # Defaults to 'assets' this should match config.assets.prefix in your rails config/application.rb
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
Does anyone know why it would fail at this task at all?