capistrano cannot run ssh: no such file or directory - deployment

I'm new to capistrano and I'm trying to set up a test project, but as you can guess, without much success. When I run cap deploy:update, I get following output:
$ cap deploy
* 2014-12-27 21:48:06 executing `deploy'
* 2014-12-27 21:48:06 executing `deploy:update'
** transaction: start
* 2014-12-27 21:48:06 executing `deploy:update_code'
executing locally: "git ls-remote git#github.com:hstandaert/test.git production"
command finished in 1281ms
* executing "git clone -q -b production git#github.com:hstandaert/test.git/customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807 && cd /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807 && git checkout -q -b deploy 5604624725df4d3c7dd4f88fc77cfd5d9d8ddf26 && (echo 5604624725df4d3c7dd4f88fc77cfd5d9d8ddf26 > /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807/REVISION)"
servers: ["ssh.stocksolutions.be"]
stocksolutions.be#ssh.stocksolutions.be's password:
stocksolutions.be#ssh.stocksolutions.be's password:
[ssh.stocksolutions.be] executing command
** [ssh.stocksolutions.be :: out] error: cannot run ssh: No such file or directory
** [ssh.stocksolutions.be :: out] fatal: unable to fork
command finished in 1611ms
*** [deploy:update_code] rolling back
* executing "rm -rf /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807; true"
servers: ["ssh.stocksolutions.be"]
[ssh.stocksolutions.be] executing command
command finished in 957ms
failed: "sh -c 'git clone -q -b production git#github.com:hstandaert/test.git /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807 && cd /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807 && git checkout -q -b deploy 5604624725df4d3c7dd4f88fc77cfd5d9d8ddf26 && (echo 5604624725df4d3c7dd4f88fc77cfd5d9d8ddf26 > /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807/REVISION)'" on ssh.stocksolutions.be
And here's the deploy.rb file:
begin
require 'colored'
rescue LoadError
$stderr.puts <<-INSTALL
You need the both the capistrano-ext and colored gems to deploy this application
Install the gems like this:
gem install colored
INSTALL
exit 1
end
set :application, "stocksolutions"
set :repository, "git#github.com:hstandaert/test.git"
set :branch, "production"
set :user, 'stocksolutions.be'
set :deploy_to, "/customers/4/b/b/#{user}/httpd.www/private"
set :use_sudo, false
set :scm, :git
default_run_options[:pty] = true
server "ssh.stocksolutions.be", :app, :web
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
Anyone who can spot my mistake?

Your log seems to suggest that either there is no ssh client installed in your deployment server, or the command cannot be found in the server's PATH.
Try if cloning the repo via https instead of ssh will work, by changing the following:
BEFORE
set :repository, "git#github.com:hstandaert/test.git"
AFTER
set :repository, "https://github.com/hstandaert/test.git"
You'll be asked to provide your login credentials for github to be able to clone the repo.

Related

capifony no such file or directory on cap deploy

i've the following easy capifony script to copy the local project to my server:
set :application, "project"
set :domain, "88.88.88.88"
set :deploy_to, "/var/www/project"
set :app_path, "app"
set :user, "root"
set :scm, :git
set :repository, "file:///Users/berlin/vagrant-workspace/essen"
set :deploy_via, :capifony_copy_local
set :use_composer, true
set :use_composer_tmp, false
set :copy_vendors, true
role :web, domain
role :app, domain, :primary => true
set :use_sudo, false
set :keep_releases, 3
logger.level = Logger::MAX_LEVEL
This is my output for cap:deploy:setup:
* 2014-10-06 21:55:38 executing `deploy:setup'
* executing "mkdir -p /var/www/project /var/www/project/releases /var/www/project/shared"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
command finished in 119ms
* executing "chmod g+w /var/www/project /var/www/project/releases /var/www/project/shared"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
command finished in 144ms
And then i can't deploy because of a missing folder. It looks like that the script doesn't create the folder inside releases.
cap deploy
* 2014-10-06 21:55:59 executing `deploy'
* 2014-10-06 21:55:59 executing `deploy:update'
** transaction: start
* 2014-10-06 21:55:59 executing `deploy:update_code'
triggering before callbacks for `deploy:update_code'
--> Updating code base with capifony_copy_local strategy
--> Using Copy Local Strategy
executing locally: "git ls-remote file:///Users/berlin/vagrant-workspace/project HEAD"
command finished in 12ms
* getting (via checkout) revision a7ba07ac38fee4b5375c6d383886a906c1a551d5 to /var/folders/l6/ptd6l19s2vb98z6bbnb1k7b00000gq/T/20141006195559
executing locally: git clone -q file:///Users/berlin/vagrant-workspace/project /var/folders/l6/ptd6l19s2vb98z6bbnb1k7b00000gq/T/20141006195559 && cd /var/folders/l6/ptd6l19s2vb98z6bbnb1k7b00000gq/T/20141006195559 && git checkout -q -b deploy a7ba07ac38fee4b5375c6d383886a906c1a551d5
command finished in 72ms
* 2014-10-06 21:55:59 executing `symfony:composer:install'
triggering before callbacks for `symfony:composer:install'
* 2014-10-06 21:55:59 executing `symfony:composer:copy_vendors'
--> Copying vendors from previous release
* executing "vendorDir=/var/www/project/current/vendor; if [ -d $vendorDir ] || [ -h $vendorDir ]; then cp -a $vendorDir /var/www/project/releases/20141006195559; fi;"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
command finished in 103ms
* 2014-10-06 21:56:00 executing `symfony:composer:get'
* executing "if [ -e /var/www/project/releases/20141006195559/composer.phar ]; then echo 'true'; fi"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
command finished in 90ms
--> Downloading Composer
* executing "sh -c 'cd /var/www/project/releases/20141006195559 && curl -s http://getcomposer.org/installer | php'"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
*** [err :: 88.88.88.88] sh: line 0: cd: /var/www/project/releases/20141006195559: No such file or directory
command finished in 106ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/project/releases/20141006195559; true"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
command finished in 102ms
failed: "sh -c 'sh -c '\\''cd /var/www/project/releases/20141006195559 && curl -s http://getcomposer.org/installer | php'\\'''" on 88.88.88.88
I can't find any solution.
Does anybody have an idea for my problem? Thank you very much.
If someone will have the same problem. This is a working script for me:
set :application, "project"
set :domain, "88.88.88.88"
set :deploy_to, "/var/www/project"
set :app_path, "app"
set :user, "root"
set :scm, :git
set :repository, "file:///Users/berlin/vagrant-workspace/project"
set :deploy_via, :capifony_copy_local
set :use_composer, true
set :use_composer_tmp, true
role :web, domain
role :app, domain, :primary => true
set :use_sudo, false
set :keep_releases, 3
set :shared_files, ["app/config/parameters.yml"]
set :shared_children, [app_path + "/logs"]
#logger.level = Logger::MAX_LEVEL
after "deploy:finalize_update" do
capifony_pretty_print "--> Set permissions for writable directories"
run "chown -R www-data:www-data #{latest_release}/#{cache_path}"
run "chown -R www-data:www-data #{latest_release}/#{log_path}"
run "chmod -R 777 #{latest_release}/#{cache_path}"
puts "✔"
end
I don't know exactly the difference, but this snippet works fine.

Capistrano ERROR: Repository not found

Running cap deploy returns the error
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly
failed: "env PATH=$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH sh -c 'if [ -d .../shared/cached-copy ]; then cd .../shared/cached-copy &&
git fetch -q origin && git fetch --tags -q origin && git reset -q
--hard e54354271256196e54354271256196 && git clean -q -d -x -f; else git clone -q -b new_front git#github.com:myapp.git
.../shared/cached-copy && cd /shared/cached-copy && git checkout -q -b
deploy ced405a4d2b184ccadf844185e54354271256196; fi'" on
192.111.111.111
but when i ssh to the server and run that exact command it works.
I've tried deleting the cached-copy and commenting set :deploy_via, "remote_cache" as mentioned in Cap deploy - ERROR: Repository not found but nothing works.
thanks
EDIT:
Similar issue:
https://gist.github.com/ParkinT/2432735
I had to run:
ssh-add
to add my identity to the authentication agent.
Turns out the problem was with ssh agent forwarding.
https://help.github.com/articles/using-ssh-agent-forwarding
Capistrano was setup
ssh_options[:forward_agent] = true
Locally I had two ssh keys, and somehow the one used locally was not the same one being used via the forward_agent. If you have a key on the server you can set
ssh_options[:forward_agent] = false
Otherwise, clear your keys and add just the one you need (on mac, ssh-add -D and ssh-add path/to/key).

Capistrano deploy from local machine

Im trying to create a new user to deploy my application from my local machine to my external server.
I've got it working using root but understand it's not secure to use root, therefore I want to create a user called 'deployer'. I've added this user to my external server and copied my local is_rsa.pub key to /.ssh/authorized_keys on the server, however when I run cap development deploy I keep getting the following error:
failed: "sh -c 'if [ -d /var/www/vhosts/xyz.co.uk/shared/cached-copy ]; then cd
/var/www/vhosts/xyz.co.uk/shared/cached-copy && git fetch -q origin && git fetch --
tags -q origin && git reset -q --hard 2b738f4ca8008dcf9e84c4be5d63d906a7bfd760 && git clean
-q -d -x -f; else git clone -q git#github.com:xyz/xyz.co.uk.git
/var/www/vhosts/xyz.co.uk/shared/cached-copy && cd /var/www/vhosts/xyz.co.uk/shared/cached-
copy && git checkout -q -b deploy 2b738f4ca8008dcf9e84c4be5d63d906a7bfd760; fi'" on
x.xx.xx.xxx
If I run ssh -T git#github.com on the external server it says:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
This username is not deployer though, I assume its the username of the github account.
Any ideas what I need to do? Do I need to create the deployer user on my local machine too?
Here is my deploy.rb file:
set :stage_dir, 'app/config/deploy' # needed for Symfony2 only
set :stages, %w(production staging development)
require 'capistrano/ext/multistage'
set :application, "xyz.co.uk"
set :user, "deployer" # The server's user for deploys
set :normalize_asset_timestamps, false
set :repository, "git#github.xyz/xyz.co.uk.git"
set :scm, :git
set :keep_releases, 3
after "deploy:update", "deploy:cleanup"
set :use_sudo, false
set :web_path, "web"
set :shared_files, ["app/config/parameters.yml"]
set :shared_children, [app_path + "/logs", web_path + "/uploads"]
set :use_composer, true
set :update_vendors, true
set :dump_assetic_assets, true
set :deploy_via, :remote_cache
#logger.level = Logger::MAX_LEVEL
after "deploy:update_code" do
capifony_pretty_print "--> Ensuring cache directory permissions"
run "setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX #{latest_release}/#{cache_path}"
run "setfacl -dR -m u:www-data:rwX -m u:`whoami`:rwX #{latest_release}/#{cache_path}"
capifony_puts_ok
end
deveopment.rb file:
server 'x.xx.xx.xxx', :app, :web, :db, :primary => true
ssh_options[:port] = 1234
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :deploy_to, "/var/www/vhosts/xyz.co.uk"
set :symfony_env_prod, "dev"
set :branch, "develop"
# Need to clear *_dev controllers
set :clear_controllers, false
Thanks
You want to have the target machine use your local SSH credentials to authenticate to Github. Do this by putting the following two entries into your deploy.rb
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
Or, another way is to go to your Github repo and add the public SSH key of your target server as a deploy key
https://github.com/your_github/your_repo/settings/keys
This gives the target server checkout access to only the specified repository without having to use your personal SSH key.
The problem was because the 'deployer' user didn't have write permissions on the server.

Deploy failed with Gitolite and Capistrano

In a project, I use gitolite and capistrano. It's work fine for another developper.
The issue is it's doesn't work for me : I can't actually deploy with capistrano.
When I run the cap deploy command, it ask me the password of the server (here, ok) and the password of the gitolite, which doesn't exist.
C:\wamp\www\miiaou>cap deploy
* ←[32m2012-12-12 15:12:34 executing `deploy'←[0m
* ←[32m2012-12-12 15:12:34 executing `deploy:update'←[0m
** transaction: start
* ←[32m2012-12-12 15:12:34 executing `deploy:update_code'←[0m
updating the cached checkout on all servers
←[33mexecuting locally: "git ls-remote gitolite#miiaou.fr:miiaou master"←[0m
←[2;37mcommand finished in 1351ms←[0m
* ←[33mexecuting "if [ -d /home/miiaou/miiaou_prod/shared/cached-copy ]; then
cd /home/miiaou/miiaou_prod/shared/cached-copy && git fetch -q origin && git fet
ch --tags -q origin && git reset -q --hard 117b2bb34817d89a1fbe34f1891ac3c823a23
fce && git clean -q -d -x -f; else git clone -q gitolite#miiaou.fr:miiaou /home/
miiaou/miiaou_prod/shared/cached-copy && cd /home/miiaou/miiaou_prod/shared/cach
ed-copy && git checkout -q -b deploy 117b2bb34817d89a1fbe34f1891ac3c823a23fce; f
i"←[0m
servers: ["miiaou.fr"]
Password:
[miiaou.fr] executing command
** [miiaou.fr :: out] Error reading response length from authentication socket.
** [miiaou.fr :: out] gitolite#miiaou.fr's password:
Password:
** [miiaou.fr :: out]
** ←[31m[miiaou.fr :: out] Permission denied, please try again.
** gitolite#miiaou.fr's password:←[0m
Password:
** [miiaou.fr :: out]
** ←[31m[miiaou.fr :: out] Permission denied (publickey,password).
** fatal: The remote end hung up unexpectedly←[0m
←[2;37mcommand finished in 36755ms←[0m
*** [←[34mdeploy:update_code←[0m] ←[34mrolling back←[0m
* ←[33mexecuting "rm -rf /home/miiaou/miiaou_prod/releases/20121212141318; tru
e"←[0m
servers: ["miiaou.fr"]
[miiaou.fr] executing command
←[2;37mcommand finished in 133ms←[0m
failed: "if [ -d /home/miiaou/miiaou_prod/shared/cached-copy ]; then cd /home/mi
iaou/miiaou_prod/shared/cached-copy && git fetch -q origin && git fetch --tags -
q origin && git reset -q --hard 117b2bb34817d89a1fbe34f1891ac3c823a23fce && git
clean -q -d -x -f; else git clone -q gitolite#miiaou.fr:miiaou /home/miiaou/miia
ou_prod/shared/cached-copy && cd /home/miiaou/miiaou_prod/shared/cached-copy &&
git checkout -q -b deploy 117b2bb34817d89a1fbe34f1891ac3c823a23fce; fi" on miiao
u.fr
I don't understand why it need a password because the ssh keys works.
Can anybody help me?
Thanks
edit : if that help, here my deploy.rb
require "bundler/capistrano"
# Rails 3.1 : laod capistrano task to precompile assets
# bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile
load "deploy/assets"
set :stages, %w(production)
set :default_stage, "production"
set :application, "miiaou"
set :repository, "gitolite#miiaou.fr:#{application}"
set :domain, "miiaou.fr"
# 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/miiaou/#{application}_prod"
set :shared_path, "/home/miiaou/#{application}_prod/shared"
set :scm, "git"
set :branch, "master"
# Agent Forwarding : use local keys for git
ssh_options[:forward_agent] = true
set :deploy_via, :remote_cache
default_run_options[:pty] = true
ssh_options[:paranoid] = false
set :user, "root"
set :runner, "root"
set :use_sudo, false
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
# Add RVM's lib directory to the load path.
#$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
#require "rvm/capistrano"
#set :rvm_ruby_string, '1.9.2'
task :clean_assets, :roles => :app do
run "rm -rf #{shared_path}/assets/*"
end
task :more_symlinks, :roles => :app do
# linkage des fichiers de config
%w(database).each do |config_file|
run "ln -nfs #{shared_path}/config/#{config_file}.yml #{release_path}/config/#{config_file}.yml"
end
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
end
task :restart_daemons, :roles => :app do
#run "cd #{release_path} && bundle exec whenever --set 'environment=#{rails_env}' --update-crontab"
#run "cd #{release_path} && RAILS_ENV=#{rails_env} ruby script/delayed_job restart"
end
# 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 "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
before :'deploy:assets:precompile', :more_symlinks

Capistrano Deployment: a Task before `deploy:finalize_update` Is not Executed

I'm using Capistrano v2.13.4 for deployment.
A Capistrano task (deploy:special_treats) before deploy:finalize_update is not executed.
The task deploy:special_treats does some preparation (setup the internet access) for bundle:install, otherwise, bundle:install will not be able to reach the Internet ([out :: servername] Could not reach https://rubygems.org/
In config/deploy.rb
before 'deploy:finalize_update', 'deploy:special_treats'
and
namespace :deploy do
task :special_treats do
run "echo 'something special treats: setup the Internet access'"
end
end
The result for cap deploy:update
$ cap deploy:update
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "svn info https://svnlinks --username username --password password --no-auth-cache -rHEAD"
command finished in 10336ms
* getting (via export) revision 33268 to /tmp/20120927171608
executing locally: svn export -q --username username --password password --no-auth-cache -r33268 https://svnlinks /tmp/20120927171608
command finished in 79314ms
* processing exclusions...
* Compressing /tmp/20120927171608 to /tmp/20120927171608.tar.gz
executing locally: tar czf 20120927171608.tar.gz 20120927171608
command finished in 1401ms
servers: ["servername"]
** sftp upload /tmp/20120927171608.tar.gz -> /tmp/20120927171608.tar.gz
[servername] /tmp/20120927171608.tar.gz
[servername] done
* sftp upload complete
* executing "cd /usr/website/rr/releases && tar xzf /tmp/20120927171608.tar.gz && rm /tmp/20120927171608.tar.gz"
servers: ["servername"]
[servername] executing command
command finished in 774ms
* executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* executing `bundle:install'
* executing "cd /usr/website/rr/releases/20120927171608 && bundle install --gemfile /usr/website/rr/releases/20120927171608/Gemfile --path /usr/website/rr/shared/bundle --deployment --quiet --without development
test"
servers: ["servername"]
[servername] executing command
** [out :: servername] Could not reach https://rubygems.org/
command finished in 1403ms
*** [deploy:update_code] rolling back
* executing "rm -rf /usr/website/rr/releases/20120927171608; true"
servers: ["servername"]
[servername] executing command
command finished in 344ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3-p194' -c 'cd /usr/website/rr/releases/20120927171608 && bundle install --gemfile /usr/website/rr/releases/20120927171608/Gemfile --path
/usr/website/rr/shared/bundle --deployment --quiet --without development test'" on servername
I just had the same issue but in the after deploy:finalize_update trigger. The difference is that my script works in another machine for a long time.
I don't have capistrano locked as a gem in the Gemfile, so I tried reverting to the same version of the working machine which is 2.6.0 but that did not fix it.
After some research and several trials, I have found some issues at the github project like this that leads to that but looks like folks can't fully reproduce it.
I have then headed to the docs and browsing I found that Capistrano behaviors have been affected by recent changes on the 0.9.x versions of rake that have to do with namespace conflicts as you can see in this brief and tiny note that can be found at the deploy:create_symlink section of Capistrano Tasks wiki page
I did not have time to fix the script to work with latest versions of both rake and capistrano but I was able to have it back working on a different machine by reverting rake to version 0.8.7.
I hope this can get you going and provide some clues towards the solution.