Capistrano cap deploy:setup does not create any files - ruby-on-rails

I don't get any error message while I execute cap deploy:setup. It attempts to create folder /myapp as mkdir -p /home/user/apps/myapp, and also other folders (releases, shared). There is no permission issue as I can execute mkdir -p /home/user/apps/myapp without any error in terminal. Furthermore, cap deploy:check gives You appear to have all necessary dependencies installed message. Am I supposed to have those folders created with cap deploy:setup? If so, why am I not getting any error message and also the folders created?
Here's my config/deploy.rb file:
set :application, "myapp"
set :location, "myserver"
set :domain, "apps.mydomain.com"
set :user, "app_admin"
set :repository, "svn+ssh://app_admin#192.168.XXX.XXX/home/svn/myapp"
set :svn_username, "svn_admin"
set :svn_password, "password"
set :use_sudo, false
set :scm, :subversion
default_run_options[:pty] = true
role :web, location
role :app, location
role :db, location, :primary => true
set :deploy_to, "/home/app_admin/#{application}"
set :deploy_via, :checkout
ssh_options[:forward_agent] = true
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

What capistrano version? What OS?
I have problems with Capistrano in Ubuntu - try Windows! I've usually found that Windows is the best server platform. Except for the infrequent crashes, windows server is very powerful.

Related

How can I get Capistrano to deploy without prompting for a password?

When I run cap deploy at a certain point towards the end of the process, I get a password prompt...
** keeping 5 of 6 deployed releases
* executing "sudo -p 'sudo password: ' rm -rf /opt/deployed_rails_apps/myapp/releases/20120922200242"
servers: ["myhost.com"]
[username#myhost.com] executing command
Password:
Is there a way I can get it to complete without prompting me to enter a password?
Here's my deploy.rb...
require "bundler/capistrano"
require "rvm/capistrano"
set :rvm_ruby_string, 'ruby-1.9.3-p194#run_passenger'
set :rvm_type, :user
set :application, 'myapp'
set :repository, 'git#github.com:fakename/myrepository.git'
set :deploy_to, "/opt/deployed_rails_apps/#{application}"
set :scm, "git"
set :branch, "master"
set :deploy_via, :remote_cache
set :keep_releases, 5
after "deploy:update", "deploy:cleanup"
load 'deploy/assets'
role :app, 'username#myhost.com'
role :web, 'username#myhost.com'
namespace :deploy do
task :start, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
end
Assuming your deployment user has appropriate permissions and you don’t need to use sudo, you can set :use_sudo to false and Capistrano won’t use it.
Just add
set :use_sudo, false
to your deploy.rb.
Set up your SSH public key on the machine you're deploying to. This isn't a Capistrano thing. Here's one guide. There are many others that you can find with a quick search.
If you really need root permission in order to delete files under /opt/deployed_rails_apps/myapp/releases/ then you can edit the /etc/sudoers file to allow your deploy user to use sudo without the password.
But I suspect the answer by #matt using set :use_sudo, false should take care of your problem.

Capistrano Deploy Error

I've recently had to make some updates to an app that I haven't touched in about a year. When attempting to deploy with Capistrano (via Github), I get this error:
[deploy:update_code] exception while rolling back: IOError, closed stream
Full logged error here: https://gist.github.com/2829751
I reinstalled my server's SSH key after the Github SSH security scare. Nothing should have changed on the remote server, and deploying worked fine previously. The only significant change on my local system is moving to RVM.
Any ideas what's causing the error?
Here's my deploy.rb file, if that helps:
default_run_options[:pty] = true
set :domain, 'xxx.xxx.xxx'
set :repository, "XXX MY REPO XXX"
set :branch, 'master'
set :password, 'XXXXXXX'
set :deploy_to, "/var/www/#{domain}"
set :scm, :git
set :repository_cache, "git_cache"
set :deploy_via, :remote_cache
ssh_options[:paranoid] = false
set :user, "XXX"
set :runner, user
set :use_sudo, true
set :rails_env, 'production'
role :app, domain # multiple domains can be added here for parallel deployment (i.e. test_app)
role :web, domain
role :db, domain, :primary => true
namespace :deploy do
task :start, :roles => :app do
run "touch #{release_path}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{release_path}/tmp/restart.txt"
end
end
deploy.task :cold do
deploy.update
deploy.create_db
deploy.migrate
deploy.restart # Change to start if we're using mongrels
end
after "deploy:update_code", :update_config
after "deploy:restart", "delayed_job:restart"
after "deploy", "deploy:cleanup"
#links config files from shared to the release path and mongrel path after deployment
desc "Create all symlinks and files needed for app activation ofter deployment"
task :update_config, :roles => :web do
run "ln -s -f /var/www/#{domain}/shared/database.yml #{release_path}/config/database.yml"
run "ln -s -f /var/www/#{domain}/shared/app.yml #{release_path}/config/app.yml"
run "ln -s -f /var/www/#{domain}/shared/cache #{release_path}/public/cache"
run "ln -s -f /var/www/#{domain}/shared/survey_cache #{release_path}/public/surveys"
run "ln -s -f /var/www/#{domain}/shared/surveys #{release_path}/surveys"
end
desc "changes ownership to cbdsm:git"
task :update_permissions, :roles => :web do
sudo "chown -R #{user}:git /var/www/#{domain}"
end
namespace :delayed_job do
desc "Start the delayed_job process"
task :start, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} script/delayed_job -n 3 start"
end
desc "Stop the delayed_job process"
task :stop, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} script/delayed_job stop"
end
desc "Restart the delayed_job process"
task :restart, :roles => :app do
delayed_job.stop
delayed_job.start
end
end
UPDATE: This seems to be a problem set :use_sudo, true. Removing that line and any commands which require sudo seemed to fix the problem. It's still not entirely clear to me what changed--that made that line problematic. It worked fine before.
Additionally, I removed the default_run_options[:pty] = true line.
As posted above:
This seems to be a problem set :use_sudo, true. Removing that line and any commands which require sudo seemed to fix the problem. It's still not entirely clear to me what changed--that made that line problematic. It worked fine before.
Additionally, I removed the default_run_options[:pty] = true line.
In these cases post the /config/deploy.rb would help...
BTW, how do you set the :deploy_via setting? Try to change this to :remote_cache (from :copy):
set :deploy_via, :remote_cache
and see what happens.

Deployment issues with capistrano

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

Sudo doesn't have access to shell commands when deploying with Capistrano

I'm deploying my Rails 3 app using capistrano.
I have on user (deploy) who's been added to sudoers. This is the user I'm deploying with.
When I log on to the server as deploy I have access to all of the gem commands I need .ie: bundle, whenever etc.
Capistrano seems to be running as sudo though, and when I try:
sudo whenever
I get
sudo: whenever: command not found
This means each time I try to deploy, it fails and rolls back.
I've tried setting :use_sudo to false in my deploy.rb file but still no luck
set :user, "deploy"
set :runner, user
set :use_sudo, false
Any suggestions?
Here's my complete deploy script in case there's anything in there I've missed:
require 'config/boot'
require 'hoptoad_notifier/capistrano'
require 'capistrano/ext/multistage'
require "whenever/capistrano"
#
set :whenever_command, "bundle exec whenever"
set :application, "MYAPP"
set :repository, "git#github.com:myAccount/myRepos.git"
# only keep 3 previous releases after cleanup
set :keep_releases, 3
set :scm, "git"
set :scm_user, "me"
set :branch, lambda {rails_env}
set :deploy_to, lambda {"/var/www/#{application}/#{rails_env}"}
default_run_options[:pty] = true
role :web, "xxx.xxx.xxx.xxx" # Your HTTP server, Apache/etc
role :app, "xxx.xxx.xxx.xxx" # This may be the same as your `Web` server
role :db, "xxx.xxx.xxx.xxx", :primary => true # This is where Rails migrations will run
set :user, "deploy"
set :runner, user
set :use_sudo, false
ssh_options[:paranoid] = false
ssh_options[:port] = 22
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app do
run " touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
namespace :bundle do
desc "run bundle install"
task :install do
run "cd #{current_release} && bundle install"
end
end
namespace :tail do
desc "Tail the current environment's log file"
task :log, :roles => :app do
stream "tail -f #{shared_path}/log/#{rails_env}.log"
end
desc "Tail the new relic log file"
task :new_relic, :roles => :app do
stream "tail -f #{shared_path}/log/new_relic.log"
end
end
before "deploy:restart", "bundle:install"
after "deploy:restart", "deploy:cleanup"
after "deploy:restart", "whenever:update_crontab"
on server run which whenever or whereis whenever you should get full path to the command put it into script:
set :whenever_command, "path_to-whenever"
It's not clean solution but might work.
Another solution might be sudo reconfiguration, go to /etc/sudoers and have a look on env_keep adding PATH might have been important, to keep all the stuff important for application you could use rvm, capistrano-rvm integration and put all the displayed variables from rvm info to env_keep, theoreticaly it should work, just be careful to not mess anything

Capistrano 'reaper not found'

I'm new to deploying with Capistrano, and I'm trying the following:
deploy.rb:
set :application, "example.co.uk"
# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
set :deploy_to, "/home/example/#{application}"
# SCM Options
default_run_options[:pty] = true # Must be set for the password prompt from git to work
ssh_options[:forward_agent] = true # Agent forwarding keys
set :repository, "git#github.com:mongeese/example.git" # Your clone URL
set :scm, "git"
set :branch, "master"
set :deploy_via, :remote_cache
set :user, "james" # The server's user for deploys
role :app, "example.co.uk"
role :web, "example.co.uk"
role :db, "example.co.uk", :primary => true
set :use_sudo, false
I get the following output:
* executing `deploy:restart'
* executing "/home/example/example.co.uk/current/script/process/reaper"
servers: ["example.co.uk"]
[example.co.uk] executing command
** [out :: example.co.uk] sh: /home/example/example.co.uk/current/script/process/reaper: not found
command finished
The "james" user can sudo. If I take out :use_sudo, I get the following error:
* executing "sudo -p 'sudo password: ' -u app /home/example/example.co.uk/current/script/process/reaper"
servers: ["example.co.uk"]
[example.co.uk] executing command
** [out :: example.co.uk] sudo: unknown user: app
command finished
I'm obviously missing something completely, as Google only seems to turn up old results about this.
There must have been a problem with the recipes, the following override works fine:
set :application, "example.co.uk"
# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
set :deploy_to, "/home/example/#{application}"
# SCM Options
default_run_options[:pty] = true # Must be set for the password prompt from git to work
ssh_options[:forward_agent] = true # Agent forwarding keys
set :repository, "git#github.com:example/MyRepo.git" # Your clone URL
set :scm, "git"
set :branch, "master"
set :deploy_via, :remote_cache
set :user, "james" # The server's user for deploys
role :app, "example.co.uk"
role :web, "example.co.uk"
role :db, "example.co.uk", :primary => true
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
end
For people who encounter the same issue, have a glance to :
http://capitate.rubyforge.org/recipes/deploy.html#deploy:restart
When calling the "cap deploy" command, "update" + "restart" in the "deploy" namespace are called.
Default behaviour for "restart" is to call the "script/process/reaper" script under the current path. In James's answer, "restart" is overridden with the below command :
run "touch #{current_path}/tmp/restart.txt"
For example, people using unicorn should process like :
#launch unicorn
task :start, roles: :app, except: { no_release: true } do
run "cd #{current_path} && bundle exec unicorn_rails -c config/unicorn.rb -E #{rails_env} -D"
end
#stop unicorn
task :stop, roles: :app, except: { no_release: true } do
run "kill -KILL -s QUIT `cat #{shared_path}/pids/unicorn.pid`"
end
#when calling "cap deploy", files will be updated with #update# task (default behaviour),
#then "restart" task will be called (overridden below)
task :restart, roles: :app, except: { no_release: true } do
stop
start
end
Hope my contribution will be helpful to someone...

Resources