Deploying on a VPS using the Capistrano gem - ruby-on-rails

I'm trying to deploy a Rails app on a VPS using the capistrano gem. I want to deploy it from my local machine to the VPS. I'm not using any repositories like Github or SVN.
So, I've installed the capistrano gem and ran 'bundle'. And added the following lines:
Capfile
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :rvm_ruby_string, 'ruby-1.9.3-p194#gemset'
deploy.rb
set :user, 'deploy'
set :application, "my_app"
set :scm, :none
set :deploy_via, :copy
set :deploy_to, "/home/#{user}/#{application}"
set :use_sudo, false
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
role :web, '1.2.3.4'
role :app, '1.2.3.4'
role :db, '1.2.3.4', :primary => true
namespace :deploy do
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
However, after running 'cap deploy:setup' on local, I get the following error:
RVM - Capistrano integration was extracted to a separate gem, install: `gem install rvm-capistrano` and remove the `$LOAD_PATH.unshift` line, note also the 'set :rvm_type, :user' is now the default (instead of :system). (RuntimeError)
I'm not sure if I should use the rvm-capistrano gem. I'm a total newbie in deployments, detailed or step by step instructions would really help. Thanks.

Seems like you need to add
gem "rvm/capistrano"
to your Gemfile and then remove the unshift line (comment out)

Related

block in materialize Could not find multi_json-1.8.0 in any of the sources rails

Here is my deploy.rb
require "bundler/capistrano"
set :rvm_ruby_string, "ruby-2.0.0-p247"
set :rvm_type, :user
set :application, "myapp"
set :repository, "git#bitbucket.org:user/myapp.git"
set :user, "my-server-username-ssh"
set :branch, "master"
set :deploy_to, "/var/rails_apps/myapp" # I have current, release and shared directory here
set :deploy_via, :copy
set :use_sudo, true
set :rvm_install_with_sudo, true
default_run_options[:pty] = true
set :port, 1234
set :scm, :git
role :web, "myapp.com"
role :app, "myapp.com"
role :db, "myapp.com", :primary => true
role :db, "myapp.com"
after "deploy:update_code","deploy:config_symlink"
set :rvm_type, :system
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
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
task :config_symlink do
#run "cp #{release_path}/config/database.yml.example #{release_path}/config/database.yml"
end
desc 'Re-establish database.yml'
task :set_database_symlink do
run "rm -fr #{current_path}/config/database.yml && cd #{current_path}/config &&
ln -nfs #{shared_path}/database.yml database.yml"
end
end
before 'deploy', 'rvm:install_ruby'
before 'deploy', 'rvm:create_gemset'
require "rvm/capistrano"
if i run cap deploy:migrate
I am getting error no database found error.
And when i manually run rake db:create in my server I am facing this error
/usr/local/rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find multi_json-1.8.0 in any of the sources (Bundler::GemNotFound)
How can i create and migrate my database.
Edit-1
Even i have updated my certificate using
rvm osx-ssl-certs update all
In my gem list i can fine
multi_json (1.8.2)
I already had this gem installed but I need to
bundle update multi_json
Seems like you might have requirements for multiple versions of the multi_json gem. You can try specifying the gem version like:
gem 'multi_json', '1.8.0'
Rerun the bundle command locally and checkin your Gemfile.lock before you deploy.

Amazon EC2 still uses the old code, not the newly deployed one

I am deploying code with Capistrano, this is the content of deploy.rb:
require 'bundler/capistrano'
set :application, "project_name"
set :use_sudo, false
set :scm, :git
set :repository, "git#bitbucket.org:my_name/fileito.git"
set :branch, "master"
set :deploy_via, :remote_cache
#set :deploy_via, :copy
set :user, "deployer"
set :password, "password"
set :deploy_to, "/home/deployer/project_name"
#set :app_site, "ec2-xx-xxx-xx-xxx.compute-1.amazonaws.com"
set :app_site, "xx.xxx.xxx.xxx"
role :web, app_site # Your HTTP server, Apache/etc
role :app, app_site # This may be the same as your `Web` server
role :db, app_site, :primary => true # This is where Rails migrations will run
require 'capistrano-unicorn'
after 'deploy:restart', 'unicorn:reload' # app IS NOT preloaded
after 'deploy:restart', 'unicorn:restart' # app preloaded
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano/recipes"
# Added:
after "deploy:stop", "deploy:start"
namespace :deploy do
task :start do
run "/etc/init.d/apache2 start"
end
task :stop do
run "/etc/init.d/apache2 stop"
end
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
But when I deploy the new code and check the app in the browser, I see there still the old code. What's wrong? When I take a look into the current directory, there is the new code - I manually checked the files through the cat command.
How is possible that in browser is still the old version -> the old code?
Thanks
There are a variety of reasons that this can happen. Here are a few links you should check:
Unicorn continues to use old code following deploy + restart
Unicorn restarting in old release directory
Restarting Unicorn with USR2 doesn't seem to reload production.rb settings

Rails ActiveSupport not loaded when deploying via Capistrano

I'm following this guide for deploying a rails app via capistrano: https://github.com/capistrano/capistrano/wiki/2.x-From-The-Beginning
I'm using linode as my VPS. I've done all the initial setup and cap deploy:setup/update/deploy all work. When I go to execute this command in my rails directory: $ rake RAILS_ENV=production db:schema:load. I get undefined method 'minutes' for 90:Fixnum. It seems that activesupport is somehow not installed, yet when I type rails --version, I get Rails 3.2.11. Any insight would be extremely helpful!
Here's my deploy.rb file:
require 'bundler/capistrano'
require "capistrano-rbenv"
set :rbenv_ruby_version, "1.9.3-p392"
set :application, "uganda-coords"
# Deploy from your local Git repo by cloning and uploading a tarball
set :scm, :git
set :repository, "git#github.com:benrudolph/myapp.git"
set :deploy_via, :copy
set :scm_passphrase, "mypassword"
set :branch, "master"
set :deploy_via, :remote_cache
set :rails_env, "production"
set :user, :root
set :deploy_to, "/var/www/#{application}"
set :use_sudo, false
set :ssh_options, { :forward_agent => true }
role :web, "176.58.105.165" # Your HTTP server, Apache/etc
role :app, "176.58.105.165" # This may be the same as your `Web` server
role :db, "176.58.105.165", :primary => true # This is where Rails migrations will run
namespace :deploy do
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
Turns out this had to do with using 90.minutes in my application.rb file. I still don't know why this works on dev and not production.

ror deployment with capistrano -> cap:deploy

i've a problem with the deploying.
i have a ubuntu 11.10 server, i have installed ruby 1.9.2 and rails 3.2.6 with RVM.
i have yet made the pull of my git, it's located in /home/**/idepro.git
i runned the "capify ." command and i modify the deploy.rb file.
i haven't any problem when i run the commands "cap deploy:setup" and "cap deploy:check", but when i run "cap deploy" i have a problem with the enviorment path. The error is:
** [out :: 176.58.****] /usr/bin/env: ruby
** [out :: 176.58.****] : No such file or directory
these are the ror's path:
******#******:~$ which ruby
/home/******/.rvm/rubies/ruby-1.9.2-p320/bin/ruby
and this is the value of $PATH:
******#******:~$ echo $PATH
/home/******/.rvm/gems/ruby-1.9.2-p320/bin:/home/******/.rvm/gems/ruby-1.9.2-p320#global/bin:/home/******/.rvm/rubies/ruby-1.9.2-p320/bin:/home/******/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/******/.rvm/gems/ruby-1.9.2-p320/bin
This is my deploy.rb file:
# RVM bootstrap
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
#require 'rvm/capistrano'
set :rvm_ruby_string, 'ruby1.9.2-p290'
# bundler bootstrap
require 'bundler/capistrano'
# main details
set :application, "176.58.******"
role :web, "176.58.******"
role :app, "176.58.******"
role :db, "176.58.******", :primary => true
ssh_options[:port] = ******
set :user, "******"
set :password, "******"
# server details
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :deploy_to, "/var/www/idealarm2"
set :deploy_via, :remote_cache
set :user, "passenger"
set :use_sudo, false
# repo details
set :scm, :git
set :scm_username, "passenger"
set :repository, "/home/******/idepro.git"
set :branch, "master"
set :git_enable_submodules, 1
# tasks
namespace :deploy do
task :start, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
end
#default_environment['PATH']='/home/******/.rvm/gems/ruby-1.9.2-p320/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin/:/usr/bin:/bin'
#default_environment['GEM_PATH']='/home/******/.rvm/gems/ruby-1.9.2-p320:/home/******/.rvm/gems/ruby-1.9.2-p320#global:/usr/lib/ruby/gems/1.$
Could anyone help me with the PATH configuration?
I'm using capistrano with RVM with no issues, having followed the 'Integration via the rvm-capistrano gem' section instructions at https://rvm.io//integration/capistrano/.

rails / capistrano - error compiling assets

When I deploy with capistrano I get an error (and rollback) when capistrano attempts to run assets:precompile.
I'm using rails 3.2.1, bundler 1.0.22, capistrano 2.11.2
If I run rake assets:precompile from /webapps/myapp/current it runs successfully.
error:
failed: "sh -c 'cd /webapps/myapp/releases/20120304160347 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'"
deploy.rb
require "bundler/capistrano"
load 'deploy/assets'
set :application, "myapp"
set :domain, '24.17.71.95'
set :repository, "."
set :deploy_via, :copy
set :local_repository, '/home/me/myapp/.git'
set :deploy_to, '/webapps/myapp/'
set :scm, :none #:git
set :user, 'me'
set :password, 'me$pw'
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
default_run_options[:pty] = true
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true # This is where Rails migrations will run
set :branch, 'master'
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
before "deploy:assets:precompile", "bundle:install"
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
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
As far as I know, the asset precompiling task should be one of the last (or even the last one) tasks that are beeing executed.
So please try to move
load 'deploy/assets'
out of deploy.rb into Capfile (root folder of your Rails app) and paste it as the last line of the file.
See my answer to this Stackoverflow question.
If that fails, try the advice in http://www.simonecarletti.com/blog/2012/02/heroku-and-rails-3-2-assetprecompile-error/

Resources