I am new to using git and Capistrano. I have setup everything else on my server and pushed my app onto a git repo (http://github.com/tnederlof/daily-trailer). When I go to run cap deploy:cold everything seems to be working until it tries to rake the db. Below is what I get when I run it, this is the last bunch of information I recieve and where the error occurs:
* executing "cd /var/www/dailytrailer.net/releases/20100205052047; rake RAILS_ENV=production db:migrate"
servers: ["173.203.201.168"]
[173.203.201.168] executing command
** [out :: 173.203.201.168] (in /var/www/dailytrailer.net/releases/20100205052047)
command finished
* executing `deploy:start'
[DEPRECATED] `deploy:start` is going to be removed after 2.5.9 - see http://is.gd/2BPeA
* executing "cd /var/www/dailytrailer.net/current && nohup script/spin"
servers: ["173.203.201.168"]
[173.203.201.168] executing command
** [out :: 173.203.201.168] nohup: ignoring input and appending output to `nohup.out'
** [out :: 173.203.201.168] nohup: cannot run command `script/spin': No such file or directory
command finished
failed: "sh -c 'cd /var/www/dailytrailer.net/current && nohup script/spin'" on 173.203.201.168
Can someone please help me figure out what script/spin is all about?
Thank you!
Do you know what you're trying to use for an app server? If it's Passenger, then you've got something screwed up in your deploy.rb. (Post that file if you want more help debugging this.) If it's mongrel, then this should be helpful.
http://www.rubyrobot.org/article/deploying-rails-20-to-mongrel-with-capistrano-21
so I am having the sam problem here
Everything gets executed expect for
executing `deploy:start'
[DEPRECATED] `deploy:start` is going to be removed after 2.5.9 - see http://is.gd/2BPeA
* executing "cd /srv/www/domain.com/domain/current && nohup script/spin"
servers: ["domain.com"]
[domain.com] executing command
** [out :: domain.com] nohup: ignoring input and appending output to `nohup.out'
** [out :: domain.com] nohup: cannot run command `script/spin': No such file or directory
command finished
failed: "sh -c 'cd /srv/www/domain.com/domain/current && nohup script/spin'" on domain.com
here is my deploy file don't see any problems as is
set :application, "domain"
set :repository, "git#git.assembla.com:domain.git"
set :user, "blitz"
set :use_sudo, false
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
set :deploy_to, "/srv/www/domain.com/#{application}"
#set :git_enable_submodules, 1 # Make sure git submodules are populated
set :port, 3002 # The port you've setup in the SSH setup section
#set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true
role :web, "domain.com" # Your HTTP server, Apache/etc
role :app, "domain.com" # This may be the same as your `Web` server
role :db, "domain.com", :primary => true # This is where Rails migrations will run
#role :db, "domain.com" # for slave db
# If you are using Passenger mod_rails uncomment this:
# if you're still using the script/reapear helper you will need
# these http://github.com/rails/irs_process_scripts
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
# 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
desc "Make symlink for database.yml"
task :symlink_dbyaml do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
desc "Create empty database.yml in shared path"
task :create_dbyaml do
run "mkdir -p #{shared_path}/config"
put '', "#{shared_path}/config/database.yml"
end
end
after 'deploy:setup', 'deploy:create_dbyaml'
after 'deploy:update_code', 'deploy:symlink_dbyaml'
after "deploy", "deploy:cleanup"
edit:
never-mind found the ans
was using passenger and needed this in the deploy.rb
[:start, :stop].each do |t|
desc "ignore #{t} since we are using passenger"
task t do ; end
end
Related
I am installing app from my private git repository. I installed all dependencies and I am using Capistrano.I am able to run app successfully on my local machine.I am using rails -v 3.2.14 and ruby -v ruby 1.9.3p362 and linux server
when I am running cap production deploy I am getting error
......
....
sftp upload complete
* executing "cd /var/www/vhosts/..../apps/login/current && bundle exec thin -C /var/www/vhosts/....../apps/login/current/thin.yml -O restart"
servers: ["......net"]
[root#emerge126.mysitehosting.net] executing command
** [out :: root#........net] Stopping server on 127.0.0.1:8080 ...
** [out :: root#........net] /var/www/vhosts/......./apps/.../shared/bundle/ruby/1.9.1/gems/thin-1.5.0/lib/thin/daemonizing.rb:131:in 'send_signal': Can't stop process, no PID found in tmp/pids/thin.8080.pid (Thin::PidFileNotFound)
My deploy.rb file require
'bundler/capistrano'
require 'capistrano/ext/multistage'
require 'capistrano-thin'
set :stages, ["staging", "production"]
set :default_stage, "production"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :ssh_options, {
config: false
}
set :application, "myapp"
set :repository, "https://........git"
set :scm, :git
set :deploy_via, :remote_cache
set :branch, 'master'
set :deploy_to, "/var/www/vhosts/......../apps/#{application}"
set :keep_releases, 5
set :use_sudo, false
set :thin_servers, 1
set :thin_port, 8081
namespace :deploy do
namespace :db do
desc "Seed the database"
task :seed, :roles => :db do
# on_rollback { deploy.db.restore }
run_remote_rake('db:seed')
end
end
task :symlink_configs do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{shared_path}/config/auth.yml #{current_path}/config/auth.yml"
end
end
before "deploy:restart", "deploy:symlink_configs"
after "deploy:update", "deploy:cleanup"
def run_remote(cmd)
run "cd #{current_path} && #{cmd}"
end
def run_remote_rake(task)
rails_env = fetch(:rails_env, 'integration')
run_remote("rake #{task} RAILS_ENV=#{rails_env}")
end
My production.rb file
set :deploy_to, "/var/www/vhosts/....../apps/# {application}"
server 'root#.......net', :web, :app, :db, :primary => true
set :thin_port, 8081
set :rails_env, 'production'
I need some help. Its a multi rails app server. Please ask any more info if you need. I have also replaced site and github url with .... because of site security.
There is no thin process running on your server, that's why you're getting the Can't stop process, no PID found error. I suggest starting thin manually so your deploy script can then successfully restart it.
I am deploying my application to a new server which has everything installed.
I am using the following capistrano deploy.rb:
require "capistrano/ext/multistage"
require "bundler/capistrano"
set :default_environment, {
'ORACLE_HOME' => "/opt/oraclient/64/11.2.0.2/",
'LD_LIBRARY_PATH' => "$ORACLE_HOME/lib:/usr/local/lib",
'PATH' => "/opt/ruby/bin:$PATH:$ORACLE_HOME/bin"
}
SECURE_FILES = ['database.yml', 'ldap.yml', 'initializers/secret_token.rb']
set :application, "myapp"
set :use_sudo, false
set :scm, :git
set :repository, "ssh://git#hostname:7999/web/myapp.git"
set :user, "webuser"
set :deploy_via, :remote_cache
after "deploy:update_code", "custom:create_symlinks", "custom:assets_precompile", "custom:miscellaneous"
after "deploy", "deploy:migrate"
after "deploy", "deploy:cleanup"
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do ; end
end
namespace :web do
desc "Enable maintenance mode for apache"
task :enable_maintenance, :role => :web do
run "mkdir -p #{shared_path}/system"
on_rollback { run "rm -f #{shared_path}/system/maintenance.html" }
page = File.read('public/maintenance.html')
put page, "#{shared_path}/system/maintenance.html", :mode => 0644
end
desc "Disable maintenance mode for apache"
task :disable_maintenance, :role => :web do
run "rm -f #{shared_path}/system/maintenance.html"
end
end
end
namespace :custom do
desc "Creating config, bundler-GEMS symlinks"
task :create_symlinks, :roles => :app do
#Secure Configuration File Symlinks
SECURE_FILES.each do |link|
fobj = "#{release_path}/config/#{link}"
run <<-CMD
if [ -e #{fobj} ]; then rm -f #{fobj}; fi;
rm -f #{previous_release}/config/#{fobj};
ln -s #{vormetric_path}/#{application}/#{link} #{fobj};
CMD
end
#Bundler GEM Installation Symlink
shared_bundler_dir = File.join(shared_path, 'bundle')
release_bundler_dir = File.join(current_release, 'vendor/bundle')
run "ln -s #{shared_bundler_dir} #{release_bundler_dir}"
end
desc "Assets Pre-Compilation"
task :assets_precompile, :roles => :app do
run "cd #{current_release} && RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
end
desc "Miscellaneous Tasks"
task :miscellaneous, :roles => :app do
run "chmod -f +w #{current_release}/db/schema.rb"
end
end
This is box-specific deploy script myhostname.rb:
server "myhostname", :app, :web, :db, :primary => true
set :deploy_to, "/opt/web/var/myapp"
set :rails_env, "customertest"
set :branch, "staging"
Now the remote box does not have access to internet, but I have all my gems stored under vendor/cache. So it should pick up from there.(vendor/cache has nokigiri under /myapp/current/vendor/cache on remote server)
When i run
cap deploy servername
, i get the following error:
** [out :: myhost] An error occurred while installing nokogiri (1.5.9), and Bundler cannot
** [out :: myhost] continue.
** [out :: myhost] Make sure that `gem install nokogiri -v '1.5.9'` succeeds before bundling.
My remote box where the code is supposed to be deployed has the following folders set up:
/opt/web/var/myapp
/opt/web/var/myapp/current(where all the code is cloned currently)
/opt/web/var/myapp/releases
/opt/web/var/myapp/shared
I am not sure how it i supposed to pick up and install the gem.
This quote from bundler docs might be relevant (emphasis mine):
http://bundler.io/v1.9/bundle_package.html
By default, if you simply run bundle install after running bundle package, Bundler will still connect to rubygems.org to check whether a platform-specific gem exists for any of the gems in vendor/cache.
This behavior can be avoided by instead running bundle install --local. Note that this requires you to have the correctly platformed version for all of your gems already cached. The easiest way to achieve this is to run bundle package on an identical machine and then check in those vendored gems.
So, in short, you need to pass the --local flag when running bundler in the production server to avoid connecting to rubygems altogether.
The solution for use with capistrano is to set this variable in you deploy.rb file:
# deployment and quiet are used by default, we add the local flag
set :bundle_flags, "--deployment --quiet --local"
on cap deploy:cold ro cap deploy, is triggered an error
[out :: xxx.xxx.xxx.xxx] Killed
command finished in 9020ms
*** [deploy:update_code] rolling back
* executing [#<Capistrano::Command::Tree::ElseBranch:0x00000100dc5478 #condition="else", #command="rm -rf /home/yasinishyn/apps/mkv/releases/20130506084016; true", #callback=#<Proc:0x00000100dd5da0#/usr/local/rvm/gems/ruby-2.0.0-p0/gems/capistrano-2.15.3/lib/capistrano/configuration/actions/invocation.rb:13>, #options={}, #skip=false>]
servers: ["xxx.xxx.xxx.xxx"]
[xxx.xxx.xxx.xxx] executing command
command finished in 386ms
failed: "sh -c 'cd -- /home/yasinishyn/apps/mkv/releases/20130506084016 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on xxx.xxx.xxx.xxx
I have tryed many advises from stack, but nosing works for me.
my deploy.rb
deploy.rb:
require "bundler/capistrano"
server "xxx.xxx.xxx.xxx", :web, :app, :db, primary: true
set :application, "app"
set :user, "user"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git#github.com:git_user/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
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}"
run "mkdir -p #{shared_path}/config"
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"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
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"
#rake seed task
desc "Seed the database on already deployed code"
task :seed, :only => {:primary => true}, :except => { :no_release => true } do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:seed"
end
desc "Seed the database on already deployed code"
task :drop, :only => {:primary => true}, :except => { :no_release => true } do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:drop:all"
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:create:all"
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:migrate"
end
end
in my production.rb I have
config.assets.compress = true
and my capfile
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
local precompile with "bundle exec rake assets:precompile RAILS_ENV=production --trace" executes without any errors.
Where is my mistake? Hot to debug it? Or maybe somewhere is some log file for capistano in which a can look for more details?
I find an answer by my own
delete "load 'deploy/assets'" from capfile, and run
cap deploy:cold
this will work without an error, but only on initial deploy. Then as usual "sudo service nginx restart" on server, and add back deleted snippet.
And BAMM!! It works :)
You are out of RAM by the sounds of it, this question and answer helped me out - I increased the swap on digital ocean server and everything worked fine: deploy with capistrano failing
For anyone who face the same problem and Andrey answer don't work stop the server "sudo service nginx stop" then cap deploy and then start the server again "sudo service nginx start". It worked for me.
I would like to use Capistrano to deploy my app in my server
I have the deploy.rb file with the following content:
set :user, "deploy"
set :use_sudo, true
set :deploy_to, "/webapps/#{application}"
#set :deploy_via, :remote_cache #Using this option avoids to do a full repository clone
#RVM
set :rvm_type, :system #System Wide installation
set :rvm_ruby_string, 'ree#K2'
set :rvm_install_shell, :bash
before 'deploy:setup','rvm:install_rvm'
before 'deploy:setup', 'rvm:install_ruby'
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# 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 "touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
Everything works fine when i set the root user, installs RVM (system-wide installation) and even a Ruby Enterprise, but when I run 'cap deploy:setup' setting the use_sudo option and deploy user, get this:
$ cap deploy:setup
* executing `deploy:setup'
triggering before callbacks for `deploy:setup'
* executing `rvm:install_rvm'
* executing "bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)"
servers: ["myserver.com"]
Password:
[myserver.com] executing command
[myserver.com] bash -c 'bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)'
*** [err :: myserver.com] bash: line 304: /usr/local/rvm/RELEASE: Permission denied
command finished in 564ms
failed: "bash -c 'bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)'" on myserver.com
What I have to do to make this work? Do I have to adjust some settings in sudoers file?
please test with 1.1.0:
gem install rvm-capistrano
Here is the output of executing of deploy.rb with cap deploy, on ubuntu & rvm:
when executing .../bin/bundle install vendor/gem, the error comes:
* executing "cd /vol/www/emclab/current && /home/dtt/.rvm/gems/ruby-1.9.2-p290/bin/bundle install vendor/gems"
servers: ["12.34.56.78"]
[12.34.56.78] executing command
*** [err :: 12.34.56.78] /home/dtt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find bundler (>= 0) amongst [minitest-1.6.0, rake-0.8.7, rdoc-2.5.8] (Gem::LoadError)
*** [err :: 12.34.56.78] from /home/dtt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
*** [err :: 12.34.56.78] from /home/dtt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
*** [err :: 12.34.56.78] from /home/dtt/.rvm/gems/ruby-1.9.2-p290/bin/bundle:18:in `<main>'
command finished in 624ms
failed: "sh -c 'cd /vol/www/emclab/current && /home/dtt/.rvm/gems/ruby-1.9.2-p290/bin/bundle install vendor/gems'" on 12.34.56.78
Here is the output of cap invoke COMMAND='which bundle':
** [out :: 12.34.56.78] /usr/local/bin/bundle
Here is the deploy.rb:
set :application, "myapp"
set :repository, "git://github.com/myapp/myapp.git"
set :scm, :git
set :user, "dtt"
set :use_sudo, true
set :scm_passphrase, "phrase"
set :branch, "master"
set :deploy_to, "/vol/www/#{application}"
#set :deploy_via, :remote_cache
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
server "12.34.56.78", :web, :app, :db, :primary => true
#role :web, "your web-server here" # Your HTTP server, Apache/etc
#role :app, "your app-server here" # This may be the same as your `Web` server
#role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run
#role :db, "your slave db-server here"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
after "deploy", "deploy:bundle_gems"
after "deploy:bundle_gems", "deploy:restart"
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :bundle_gems do
run "cd #{deploy_to}/current && /home/dtt/.rvm/gems/ruby-1.9.2-p290/bin/bundle install vendor/gems"
end
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
Any suggestions about the error? Thanks.
Get cap to connect and tell you where bundle is installed
cap invoke COMMAND='which bundle'
If the bundle command is not found, your PATH is not set correctly. You might need to PermitUserEnvironment in the sshd running on that host. Then you can set the path manually in the deploy user's .ssh/environment file.
Is bundler installed on the remote machine?
Somewhere in your log it says:
Could not find bundler (>= 0)
The problem may be that you need to create the bundler wrapper. You can do that this way(in your deploy.rb, for example)
require "rvm/capistrano" # http://beginrescueend.com/integration/capistrano/
# rvm-capistrano settings
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"")
namespace :rvm do
task :create_bundle_wrapper, roles: :app do
run "rvm wrapper #{rvm_ruby_string} bundle bundle"
end
end
after "deploy:create_symlink", "rvm:create_bundle_wrapper"