I'm a novice with capistrano, and I'm going to deploy my app in linode on SO ubuntu 10.04 lucid 64 bits.
I'm trying to make my deploy with capistrano gem, but I get the error:
[000.00.000.00] executing command
[000.00.000.00] rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'default' -c 'cd /home/user/project/current; git fetch origin; git reset --hard master'
** [out :: 109.74.195.41] bash: /home/user/.rvm/bin/rvm-shell: No such file or directory
command finished in 330ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'default' -c 'cd /home/user/project/current; git fetch origin; git reset --hard master'" on 000.00.000.00
ubuntu#ubuntu:~/Desktop/project$
This is my deploy.rb
# RVM
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :rvm_ruby_string, 'default'
set :rvm_type, :user
# Bundler
require "bundler/capistrano"
# General
set :application, "project"
set :user, "user"
set :deploy_to, "/home/user/project"
set :deploy_via, :copy
set :use_sudo, false
# Git
set :scm, :git
set :repository, "~/project/.git"
set :branch, "master"
# VPS
role :web, "my vps ip"
role :app, "my vps ip"
role :db, "my vps ip", :primary => true
set :server, :nginx
require 'capistrano_recipes'
I have installed nginx and I want to use unicorn with nginx.
I have a directory created in home/user/project in remote vps to deploy my application there.
My ruby version in vps remote host is:
ruby 1.9.2p318 (2012-02-14 revision 34678) [x86_64-linux]
Can anyone help shed some light on what I'm doing wrong?
RVM (head or 1.11.0) now supports tasks for installing RVM/Ruby, I have an article to describe the process http://niczsoft.com/2012/03/fast-deployment-using-capistrano-rvm-and-more/
You can find my deploy.rb here: https://github.com/mpapis/ad/blob/master/config/deploy.rb
And here is description on RVM site: http://beginrescueend.com/integration/capistrano/
Also worth mentioning are the new file formats not requiring trusting: http://beginrescueend.com/workflow/projects/#ruby-versions
Related
Here's my Capistrano file:
set :application, "mydemoapp"
set :repository, "git#bitbucket.org:sergiotapia/mydemoapp.git"
set :scm, :git
set :user, "serg" # The user on the VPS server.
set :use_sudo, false
set :deploy_to, "/opt/nginx/html/#{application}"
set :deploy_via, :remote_cache
set :keep_releases, 1
set :rails_env, "production"
set :migrate_target, :latest
role :web, "192.168.1.1" # Your HTTP server, Apache/etc
role :app, "192.168.1.1" # This may be the same as your `Web` server
role :db, "192.168.1.1", :primary => true # This is where Rails migrations will run
The IP addresses above are obviously fake, I'm using the IP for my VPS
server in real life.
I ran this command, to verify that BitBucket is allowing me to access the repository:
sergiotapia#jarvis1:~/.ssh$ ssh -T hg#bitbucket.org
conq: logged in as sergiotapia.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
However, running cap deploy again, I get:
[198.211.101.99] executing command
** [192.168.1.1:: err] Permission denied (publickey).
** [192.168.1.1:: err] fatal: The remote end hung up unexpectedly
command finished in 1026ms
*** [deploy:update_code] rolling back
* executing "rm -rf /opt/nginx/html/demoapp/releases/20130601025656; true"
I tried using git clone from my SSH terminal, manually and it worked fine as expected. My project cloned to a folder properly.
It seems Capistrano is running sudo git clone instead of git clone. This is verified by myself running a sudo git clone in the same folder manually on my SSH. Same Permission denied (publickey) error.
Why isn't my Capistrano setting for :use_sudo, false being used?
I'm trying to deploy with Capistrano and RVM and even though when running cap bundler:install_bundler which is supposed to install bundler, and succeeds. After, when running cap deploy it fails with an error that bundler is not installed.
** [out :: victorstan.com] ERROR: Gem bundler is not installed, run `gem install bundler` first.
Any ideas why it installs bundler, but then can't find it, or installs it in the wrong place (i guess?). Thanks!
here is part of my deploy.rb script:
set :application, "dinner"
set :domain, "victorstan.com"
set :repository, "ssh://#{domain}/~/#{application}.git"
set :use_sudo, false
set :user, "victorstan" # The server's user for deploys
set :scm, :git
set :scm_username, "passenger"
set :deploy_to, "/srv/www/#{application}"
set :keep_releases, 2
set :branch, "master"
set :deploy_via, :copy # won't make cap prompt for password when deploying
set :scm_verbose, true
set :rvm_ruby_string, 'ruby-2.0.0-p195#dinner'
set :rvm_type, :user
set :rvm_install_type, :stable
set :whenever_command, "bundle exec whenever"
require "bundler/capistrano"
require "rvm/capistrano"
require "whenever/capistrano"
If I try to use cap to install bundler, it works:
cap bundler:install_bundler
* 2013-06-08 15:33:54 executing `bundler:install_bundler'
* executing "gem install bundler"
servers: ["victorstan.com"]
[victorstan.com] executing command
** [out :: victorstan.com] Successfully installed bundler-1.3.5
** [out :: victorstan.com] 1 gem installed
command finished in 1373ms
And here is the output when running cap deploy:
Switched to a new branch 'deploy'
command finished in 984ms
* Compressing /var/folders/w4/_6g_9lqd491_6cmhzb0kcmzh0000gn/T/20130608192600 to /var/folders/w4/_6g_9lqd491_6cmhzb0kcmzh0000gn/T/20130608192600.tar.gz
executing locally: tar czf 20130608192600.tar.gz 20130608192600
command finished in 53ms
servers: ["victorstan.com"]
** sftp upload /var/folders/w4/_6g_9lqd491_6cmhzb0kcmzh0000gn/T/20130608192600.tar.gz -> /tmp/20130608192600.tar.gz
[victorstan.com] /tmp/20130608192600.tar.gz
[victorstan.com] done
* sftp upload complete
* executing "cd /srv/www/dinner/releases && tar xzf /tmp/20130608192600.tar.gz && rm /tmp/20130608192600.tar.gz"
servers: ["victorstan.com"]
[victorstan.com] executing command
command finished in 467ms
* 2013-06-08 15:26:05 executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* 2013-06-08 15:26:05 executing `bundle:install'
* executing "cd /srv/www/dinner/releases/20130608192600 && bundle install --gemfile /srv/www/dinner/releases/20130608192600/Gemfile --path /srv/www/dinner/shared/bundle --deployment --quiet --without development test"
servers: ["victorstan.com"]
[victorstan.com] executing command
** [out :: victorstan.com] ERROR: Gem bundler is not installed, run `gem install bundler` first.
command finished in 598ms
*** [deploy:update_code] rolling back
* executing "rm -rf /srv/www/dinner/releases/20130608192600; true"
servers: ["victorstan.com"]
[victorstan.com] executing command
command finished in 513ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-2.0.0-p195#dinner' -c 'cd /srv/www/dinner/releases/20130608192600 && bundle install --gemfile /srv/www/dinner/releases/20130608192600/Gemfile --path /srv/www/dinner/shared/bundle --deployment --quiet --without development test'" on victorstan.com
is ruby-2.0.0-p195#dinner installed / created on the server?
you can ensure it is with adding:
before 'deploy:setup', 'rvm:install_ruby'
more details on using rvm-capistrano can be found here: https://github.com/wayneeseguin/rvm-capistrano#readme
I have read some more examples on setting up deploy script and i've re-arranged the order of elements of my deploy script, as well as ena
set :application, "dinner"
set :domain, "victorstan.com"
set :repository, "ssh://#{domain}/~/#{application}.git"
set :use_sudo, false
set :user, "victorstan" # The server's user for deploys
set :scm, :git
set :scm_username, "passenger"
set :scm_passphrase, "*********" # The deploy user's password
set :deploy_to, "/srv/www/#{application}"
set :keep_releases, 2
set :branch, "master"
set :deploy_via, :copy # won't make cap prompt for password when deploying
set :scm_verbose, true
set :rvm_ruby_string, :local
set :rvm_type, :user
set :rvm_install_type, :stable
set :default_shell, :bash
set :whenever_command, "bundle exec whenever"
default_run_options[:pty] = true
# before 'deploy', 'rvm:install_ruby'
before 'deploy:setup', 'rvm:install_ruby'
require "rvm/capistrano"
require "bundler/capistrano"
require "whenever/capistrano"
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
Some notable elements that have changed:
set :rvm_ruby_string set to :local instead of explicitly naming it: 'ruby-2.0.0-p195#dinner', not sure if this has any implication on the issue though, seems unlikely.
set :default_shell, :bash was another parameter I added.
And, as I mentioned, the ordering or the different DSL types might make a difference: set comes first, then before hooks, then require and then role after which comes the rest of the deploy script. Perhaps this can help someone in a similar situation.
Note, when I first tested this script I had before 'deploy', 'rvm:install_ruby' enabled, but I have since disabled it and the script continues to work...
Capistrano raises the error "ERROR: Gem bundler is not installed, run gem install bundler first."
But when I clone the project to /tmp/project of the targe server bundle runs (as root) smoothly.
The server is a Ubuntu 12.04.2 LTS, ruby was installed via rvm.
I added "source /usr/local/rvm/scripts/rvm" to the /root/.bashrc but it did not solve the problem.
require "bundler/capistrano"
set :application, 'myproject'
set :repository, "git#myproject.git"
set :branch, 'staging'
set :user, 'root'
set :domain, "mydomain"
set :deploy_to, "/var/webapps/#{application}"
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
role :db, domain
default_run_options[:pty] = true
# [and then the tasks]
TIA.
EDIT
This very same deploy script worked in another server, with ruby installed in the same way. The only difference I remember is that that server was a CentOS.
Also tried rvm wrapper rvm current bundle bundle as suggested here
Edit 2
I compared the env command via ssh and via capistrano. The following env variables were missing when env was issued by capistrano:
__array_start=0
_first=0
_second=1
escape_flag=1
GEM_HOME=/usr/local/rvm/gems/ruby-1.9.3-p392
GEM_PATH=/usr/local/rvm/gems/ruby-1.9.3-p392:/usr/local/rvm/gems/ruby-1.9.3-p392#global
IRBRC=/usr/local/rvm/rubies/ruby-1.9.3-p392/.irbrc
LC_ADDRESS=pt_BR.UTF-8
LC_IDENTIFICATION=pt_BR.UTF-8
LC_MEASUREMENT=pt_BR.UTF-8
LC_MONETARY=pt_BR.UTF-8
LC_NAME=pt_BR.UTF-8
LC_NUMERIC=pt_BR.UTF-8
LC_PAPER=pt_BR.UTF-8
LC_TELEPHONE=pt_BR.UTF-8
LC_TIME=pt_BR.UTF-8
LESSCLOSE=/usr/bin/lesspipe %s %s
LESSOPEN=| /usr/bin/lesspipe %s
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-1.9.3-p392
RUBY_VERSION=ruby-1.9.3-p392
rvm_bin_path=/usr/local/rvm/bin
rvm_debug_clr=
rvm_error_clr=
rvm_notify_clr=
rvm_path=/usr/local/rvm
rvm_prefix=/usr/local
rvm_reset_clr=
rvm_version=1.19.5 (stable)
rvm_warn_clr=
The following env vars were different:
_=/usr/bin/env # ssh
_=/bin/sh # capistrano
LANG=en_US.UTF-8 # ssh
LANG=C # capistrano
LANGUAGE=en # ssh
LANGUAGE=C # capistrano
# ssh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/rvm/bin
# capistrano
PATH=/usr/local/rvm/gems/ruby-1.9.3-p392/bin:/usr/local/rvm/gems/ruby-1.9.3-p392#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p392/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
I had a similar problem with one of my setups, though I use rbenv to manage ruby versions. The issue was that bundler was not installed on the Ruby version my project was pointing to.
I did a quick check online and you have a few options:
run rvm gemset use global && gem install bundler (installs to
global version)
edit your /.bashrc ... something along those lines
([[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm")
Running gem env may show you that you are forcing a path, and you would then need to remove the entry from ~/.gemrc or /etc/gemrc
My 2-cents
I'm a bit of a newbie when it comes to deploying and related things, so please be lenient.
I'm building a staging server for a bunch of hobby projects, and to do that, I'll need to
Support multiple Ruby versions
Support multiple running rails/other applications
Support multiple databases and related software
I also want the deploy script to allow deploying to production, if the day ever comes.
This background necessitates the use of RVM, Capistrano-multistage and Passenger Standalone (the other option being Mongrel, but as I wish to use Passenger in production, I figured it'd be safer to use Passenger in staging too). All of this makes deployment a little hairy.
I've gotten things cobbled together quite nicely, and everything else seems to work, but for some reason Passenger fails to start when commanded to do so from Capistrano. If I SSH into the box and type the command in myself it works nicely. What's wrong?
To aid you in your efforts to help me, here is a copy of my config/deploy.rb
set :application, "Appname"
set :repository, "path-to-git-repo-over-ssh"
set :scm, :git
default_run_options[:pty] = true
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"")
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
set :use_sudo, false
before 'deploy:setup', 'rvm:install_rvm' # install RVM
before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset
require "rvm/capistrano"
require "bundler/capistrano"
require 'sidekiq/capistrano'
set :deploy_via, :remote_cache
set :stages, %w(staging production)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
set :rails_env, lambda { stage }
set :startcmd, lambda { "cd #{current_path} && bundle exec passenger start -d -p #{passenger_port} -e #{rails_env} --pid-file=#{current_path}/tmp/pids/passenger.#{passenger_port}.pid #{current_path}" }
namespace :deploy do
task :stop do
run("cd #{current_path} && bundle exec passenger stop -p #{passenger_port}")
end
task :restart do
run("cd #{current_path} && touch tmp/restart.txt")
end
task :start do
run("#{startcmd}")
end
end
after "deploy:update_code" do
run "(echo \"#reboot /bin/bash -l -c '#{startcmd}' >>log/boot.out 2>>log/boot.err # from capistrano \" && cat #{release_path}/crontab.#{stage}) | crontab -"
end
And here is config/deploy/staging.rb
set :deploy_to, "/var/www/appname"
set :user, 'app-specific-user'
set :password, 'super-secret-password'
set :domain, '1.2.3.4'
server domain, :app, :web
role :db, domain, :primary => true
set :passenger_port, 1234
Well bloody hell.
On complete hunch, I removed the
default_run_options[:pty] = true
Setting from the file, and like magic it started working. Now if only someone would tell me why.
I deployed my rails 3 app onto the production server using Capistrano. The deployment is correct, the application server is correctly restarted but when I log onto the production server and go into "my_path/current", I cannot run "rails c":
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
I checked the gem list and everything seems to be correctly installed though.
My config/deploy.rb file is:
require "bundler/capistrano"
# Add RVM's lib directory to the load path.
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
# Load RVM's capistrano plugin.
require "rvm/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user # Don't use system-wide RVM
set :application, "MyApp"
set :repository, "git#github.com:user/myapp.git"
set :scm, :git
set :branch, "master"
set :scm_verbose, true
set :scm_username, "user" # GITHUB user name
set :user, "user" # VPS user name
set :scm_passphrase, "pass" # VPS password
set :deploy_to, "/home/luc/be"
set :use_sudo, false
server "my_server", :web, :app, :db, :primary => true
# start / stop application server
namespace :deploy do
task :start do
invoke_command "cd /home/luc/be/current; bundle exec thin start -C config/thin.config"
end
task :stop do
invoke_command "cd /home/luc/be/current; bundle exec thin stop -C config/thin.config"
end
task :restart do
invoke_command "cd /home/luc/be/current; bundle exec thin restart -C config/thin.config"
end
end
Try bundle exec rails c. Also check what error, if any, is thrown when you visit the page in your browser