0
votes

I am trying to have capistrano deploy my rails app to a vps.

I logged into the vps, added a new 'deployer' user and gave him sudo privileges by:

adduser deployer

and in visudo

deployer    ALL=(ALL:ALL) ALL

I installed rvm, ruby, postgres, postfix, and nginx. All using apt-get, latest version of ruby and rvm. In my gem file I'm using:

gem 'unicorn'

# Deploy with Capistrano
gem 'capistrano'
gem 'rvm-capistrano', '>= 1.3.0.rc11'

Trying to run cap deploy:setup, I came across a bunch of rvm errors, but fixed them by reinstalling rvm on cap deploy:setup using the following in my deploy.rb file, according to the capistrano github readme:

set :rvm_ruby_string, 'ruby-1.9.3-p392' # use the same ruby as used locally for deployment
set :rvm_install_ruby_params, '--1.9'      # for jruby/rbx default to 1.9 mode
set :rvm_install_pkgs, %w[libyaml openssl] # package list from https://rvm.io/packages
set :rvm_install_ruby_params, '--with-opt-dir=/usr/local/rvm/usr' # package support

before 'deploy:setup', 'rvm:install_rvm'   # install RVM
before 'deploy:setup', 'rvm:install_pkgs'  # install RVM packages before Ruby
before 'deploy:setup', 'rvm:install_ruby'  # install Ruby and create gemset, or:
before 'deploy:setup', 'rvm:create_gemset' # only create gemset
before 'deploy:setup', 'rvm:import_gemset' # import gemset from file

When I run cap deploy:cold, it goes through fine, until the end where it gives the error:

failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-1.9.3-p392' -c 'cd /home/deployer/apps/blog/releases/20130301223924 && bundle install --gemfile /home/deployer/apps/blog/releases/20130301223924/Gemfile --path /home/deployer/apps/blog/shared/bundle --deployment --quiet --without development test'" on 198.211.127.46

So I add my 'deployer' user into group 'rvm' using:

sudo usermod -G rvm deployer

And after running a cap deploy:cold, get the error:

 ** [out :: 198.211.127.46] cannot create directory `/home/deployer/apps/blog/releases/20130301223718'
 ** [out :: 198.211.127.46] : Permission denied

Any insight would be greatly appreciated. I'm almost there.

Here's my deploy.rb file:

require "bundler/capistrano"
require "rvm/capistrano"

server "198.211.127.46", :web, :app, :db, primary: true

set :port, 46000
set :application, "blog"
set :user, "deployer"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, true
set :keep_releases, 5

set :scm, "git"
set :repository, "git@bitbucket.org:myusername/#{application}.git"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

######
set :rvm_ruby_string, 'ruby-1.9.3-p392' # use the same ruby as used locally for deployment
set :rvm_install_ruby_params, '--1.9'      # for jruby/rbx default to 1.9 mode
set :rvm_install_pkgs, %w[libyaml openssl] # package list from https://rvm.io/packages
set :rvm_install_ruby_params, '--with-opt-dir=/usr/local/rvm/usr' # package support

before 'deploy:setup', 'rvm:install_rvm'   # install RVM
before 'deploy:setup', 'rvm:install_pkgs'  # install RVM packages before Ruby
before 'deploy:setup', 'rvm:install_ruby'  # install Ruby and create gemset, or:
before 'deploy:setup', 'rvm:create_gemset' # only create gemset
before 'deploy:setup', 'rvm:import_gemset' # import gemset from file
########

after "deploy", "deploy:cleanup" # keep only the last 5 releases

namespace :deploy do
  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
    sudo "mkdir -p #{shared_path}/config"
    sudo "chown deployer:deployer #{shared_path}/config" # added this to get around sftp permisssions
    put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config"

  # sudo "chmod +x #{release_path}/config/unicorn_init.sh"
  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
    # run "chmod +x #{release_path}/config/unicorn_init.sh"
  end
  after "deploy:finalize_update", "deploy:symlink_config"

  desc "Make sure local git is in sync with remote."
  task :check_revision, roles: :web do
    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
  before "deploy", "deploy:check_revision"
end
2
double check that on the remote system, /home/deployer is actually owned by use deployer? Is the file system mounted as writable?DGM
When I run 'ls -l' on '/home/deployer', this is what I see: drwxr-xr-x 7 deployer deployer 4096 Mar 1 20:30 deployerancoanco
It seems I fixed the issue by just recursively chowning the 'home' directory to the deployer user. It seems that 'releases' folder was owned by root.ancoanco

2 Answers

1
votes

Try with

chown -R deployer /home/deployer
0
votes

Make sure all of the folders are owned by deployer. :)