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.
Related
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
i cant get capistrano to fully deploy my rails app to my dreamhost VPS..
as far as i can tell its halting at creating the release directory..
$ cap deploy
i get
failed: "sh -c 'cd /home/gasloggr/gasloggr.com/releases/20120824064241 && bundle install --gemfile /home/gasloggr/gasloggr.com/releases/20120824064241/Gemfile --path /home/gasloggr/gasloggr.com/shared/bundle --deployment --quiet --without development test'" on gasloggr.com
for troubleshooting purposes i ran what was in quotes on the server itself and i received..
bash: cd: /home/gasloggr/gasloggr.com/releases/20120824064241: No such file or directory
a quick ls -alh of the releases dir, and guess what... its empty.
My deploy.rb file
require 'bundler/capistrano'
default_run_options[:pty] = false
ssh_options[:forward_agent] = true
set :use_sudo, false
set :user, "gasloggr"
set :application, "gasloggr.com"
set :repository, "git#github.com:gorelative/GasLoggr.git"
set :scm, :git
set :branch, 'master'
set :git_shallow_clone, 1
set :deploy_via, :copy
set :copy_compression, :bz2
set :rails_env, 'production'
set :deploy_to, "/home/gasloggr/#{application}"
role :web, "#{application}" # Your HTTP server, Apache/etc
role :app, "#{application}" # This may be the same as your `Web` server
role :db, "#{application}", :primary => true # This is where Rails migrations will run
# role :db, "your slave db-server here"
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
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
i have tried removing :deploy_via as well as all of the below:
set :deploy_via, :remote_cache
set :deploy_via, :copy
Please try again following the methods outlined here: http://wiki.dreamhost.com/Capistrano
This specific part may be of the most help, mentioning cap deploy:setup : http://wiki.dreamhost.com/Capistrano#Deployment_with_Capistrano
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)
I've set this up before but can't get it to work now. I want a development and production site. When I do cap deploy it'll setup a "current" symlink (not sure how I did that since for a long time it wouldn't even do that). But how do I get it to deploy and setup the necessary symlink for dev/prod?
My deploy.rb file:
#require 'bundler/capistrano'
require 'capistrano/ext/multistage'
require 'capistrano_colors'
set :stages, %w(development production)
set :default_stage, 'development'
set :application, "myapp"
set :repository, "***"
# Target directory on the server
set :deploy_to, "/var/www/#{application}"
set :scm, :git
set :deploy_via, :remote_cache
set :user, '***'
set :use_sudo, false
role :web, "68.225.130.30" # Your HTTP server, Apache/etc
role :app, "68.225.130.30" # This may be the same as your `Web` server
role :db, "68.225.130.30", :primary => true # This is where Rails migrations will run
# List of symlinks to be generated. Keys are subdirectories of release_path.
SYMLINKS = { :config => ['database.yml'],
:public => ['system'] }
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')}"
# Not working =/
#run "touch /var/www/#{current_path}/tmp/restart.txt"
end
desc "Set up application symlinks."
task :app_symlinks do
SYMLINKS.keys.each do |key|
dir = key.to_s
SYMLINKS[key].each do |path|
run "ln -nfs #{shared_path}/#{dir}/#{path} #{release_path}/#{dir}/#{path}"
end
end
end
end
my deploy/development.rb file:
set :deploy_to, "/var/www/#{application}"
set :branch, "master"
unset :rails_env
set :rails_env, "development"
UPDATE/ANSWER:
Issue was with the current_path variable. Weird since I've tried using
set :current_path, "development"
and
set :current_path, "#{application}/development"
and it didn't work. Looks like I have to set the entire path, which seems weird since I've used the latter before.
set :current_path, "/var/www/#{application}/development"
Anyone know why?
:current_path is set by capistrano based on the :deploy_to path + the :application name. You can only use :current_path within your namespaced tasks.
In other words, it's a convenience variable used for creating symlinks, restarting servers, and other tasks.
Am following a nice tutorial here and it's really helped wrap my head around some things. Rails apache and rvm all work nicely together. I'm almost finished but am getting stuck on the final part.
Basically I have the deploy file similar to what he has but cant seem to debug what he's looking for.The deploy.rb file looks like this:
#RVM Bootstrap
$:.unshift(File.expand_path('./lib',ENV['rvm_path']))
require 'rvm/capistrano'
set :rvm_ruby_string, '1.9.2-p318'
#bundler bootstrap
require 'bundler/capistrano'
#main details
set :application , "test"
role :web, "test"
role :app, "test"
role :db, "test", :primary => true
#server Details
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :deploy_to, "/var/www/test/"
set :deploy_via, :remote_cache
set :user, "passenger"
set :use_sudo, false
# repo details
set :scm, :git
set :scm_username, "passenger"
set :repository, "git#gitserver:test.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
When I attempt to deploy the application with capistrano with cap deploy:setup
I get the following error:
* executing `deploy:setup'
* executing "mkdir -p /var/www/test/ /var/www/test/releases /var/www/test/shared /var/www/test/shared/system /var/www/test/shared/log /var/www/test/shared/pids"
servers: ["test"]
connection failed for: test (SocketError: getaddrinfo: Name or service not known)
I've tinkered with it a bit. Rails webrick has no problems starting the rails application so it must be something to do with me deploying to apache. One thing to note is that the application name "app" (because test is reserved in rails) and the domain name is "test".
This mismatch could be causing problems but I have little to no experience so I'm not sure.
Can anyone point me where to debug or what it might be?
Role web, app and db need to be the URL or IP of the server that you're deploying to. Something like this:
task :staging do
set :rails_env, 'staging'
role :app, "example.com"
role :web, "example.com"
role :db, "example.com", :primary => true
end